Attachments in CloudCode

Attachment fields can be accessed in CloudCode with the following JavaScript API. This applies to fields of type="attachment", type="photo" and type="signature".

myobject.photo.present(); // false if not uploaded yet
myobject.photo.url(); // null if not uploaded yet
myobject.photo.processed('fullscreen').url();
await myobject.photo.toBuffer();
await myobject.photo.toBase64();
await myobject.mycsvfile.toText();
myobject.photo.toJSON(); // output state and urls in APIv4-compatible JSON.

To upload a file, create a new Attachment object using Attachment.create():

const photoData = Buffer.from([...]);

myobject.mycsvfile = await Attachment.create({ filename: 'data.csv', text: csvdata });
myobject.photo = await Attachment.create({ filename: 'photo.jpg', data: photoData });
await myobject.save();

Last updated