ctm.storeFile
The method of JS Bridge functionality is intended to save the file attachment as the Attachment object.
Query format
ctm.storeFile([Name, ParentId, File_url], handler)
-
Name is the name and extension that will be assigned to the file attachment;
-
ParentId is the ID of the record that stores the file attachment;
-
File_url is a local path that can be obtained with the ctm.getFile method.
Handler
Use a handler function to describe the output format of the query results, e.g., to display the results of operations or method errors for debugging purposes.
ctm.storeFile({"Name": "product_photo.png", "ParentId":"0011w00000HUnzr", "File_url": "/private/var/mobile/Containers/Data/Application/6404F6A1-0A03-434A-A1C9-CB189141BC45/tmp/photo (Monday, 15 July 2019 at 15:11:55 Moscow Standard Time).png"})
var storeString = '{"name":"test.png", "parentId": "DSFS-2342-TYRE-ADSFBA374Q8RQ8", "file_url": "/var/mobile/containers/Data/{PATH_TO_PHOTO}"}';
var storeObject = JSON.parse(storeString);
ctm.storeFile(storeObject, function(response){
console.log('Create file result', response);
})
The result:
{
"success":true,
"id":"00P-EDCEEA4B-A8D6-4E9A-ADFB-DE81FF6C5551"
}