I have a lot of files that are already in M-Files and attached to documents, and I want to attach them to a different object type as well. Is it possible to do this with the REST API?
I have a lot of files that are already in M-Files and attached to documents, and I want to attach them to a different object type as well. Is it possible to do this with the REST API?
This depends on what you mean by "attach" exactly. If you want to tag a certain document with, for instance, customer or project information, this would be done by adding/updating a property value on the document (Choose from list Customers/Projects). There are examples of how to do this via the REST API on the Developer Portal.
Typically you don't want to create duplicate content in the vault but rather help users find the documents they are looking for by adding business context to them.
I'm not trying to link a document to a new object type, what I'm trying to do is associate the file itself with the document type. I can't see an example of how to do that in the documentation. Is it not possible?
Have you seen the example of creasing an object with files here?
Yes, but that just talks about uploading new files and attaching them to an object and doesn't seem to cover the case where the file already exists in M-Files and needs to be attached to a new object.
Ahh, I understand.
So two points to my answer.
Firstly: you can do this, but you effectively have to download the file then re-upload it. So get the file content, then upload it again as per this sample.
Secondly: you should probably not do this. One primary point of M-Files is to try to avoid duplication, and copying the files sounds like you should change the process. Instead what you probably want to do is create an object and _relate_ it to the other item. You do this by creating an appropriate property on the new item and set the lookup to point to the original file.
There _are_ some reasons to copy a file at a point in time (e.g. when creating a "published" version of a source document), but they are generally the exception rather than the rule.
© 2024 M-Files, All Rights Reserved.