Copy an attachment
To copy attachments, use the server-side scripts. You can use one of the following ways:
Use the base64 object of the original attachment. Due to the specifics of the readBase64 method, the maximum size of the copied file is 10 Mb.
Example Expand sourceconst attachmentRec = new SimpleRecord('sys_attachment'); attachmentRec.get('167654133500015741'); ss.info(`Original size bytes: ${attachmentRec.size_bytes}`); // Info: Original size bytes: 92414492 const attach = new SimpleAttachment(); const base64Value = attach.readBase64(attachmentRec.sys_id); const attachCopyId = attach.writeBase64( attachmentRec.record_document_id, 'copy_of_' + attachmentRec.file_name, base64Value, attachmentRec.mime_content_type ); if (attachCopyId) { attachmentRec.get(attachCopyId); ss.info(`/record/sys_attachment/${attachCopyId}`); // Info: /record/sys_attachment/167654428100399185 ss.info(`Copy size bytes: ${attachmentRec.size_bytes}`); // Info: Copy size bytes: 0 }
Use the SimpleAttachmentService class. The maximum size of the copied file depends on the instance-wide limit that is specified in the max_file_size_upload system property.
Example Expand sourceconst attachmentRec = new SimpleRecord('sys_attachment'); attachmentRec.get('167654133500015741'); ss.info(`Original size bytes: ${attachmentRec.size_bytes}`); // Info: Original size bytes: 92414492 const importSource = new SimpleRecord('sys_import_source'); importSource.get('167647710807446665'); // From Incident Import Source const docId = ss.getDocIdByIds(importSource.sys_db_table_id, importSource.sys_id); const attach = new SimpleAttachment(); const attachUrl = attach.getAttachmentUrlById(attachmentRec.sys_id); const simpleAttach = new SimpleAttachmentService(); const docID = ss.getDocIdByIds(importSource.sys_db_table_id, importSource.sys_id); const attachCopyId = simpleAttach.createAttachmentByUrl(attachUrl, docId, `Copy_of_the_${attachmentRec.file_name}`); if (attachCopyId) { attachmentRec.get(attachCopyId); ss.info(`/record/sys_attachment/${attachCopyId}`); // Info: /record/sys_attachment/167654472004676912 ss.info(`Copy size bytes: ${attachmentRec.size_bytes}`); // Info: Copy size bytes: 92414492 }
Attachment download URL
Attachment links can be used for various purposes:
- downloading a single file from attachments.
- download all files from attachments as an archive.
- using a link to a file from attachments in HTML tags.
Apart from this, links can also be used to:
- add images to the body of the HTML field.
- add images to the widget by setting the value of the scr attribute.
Attachment records can be public or non-public. The publicity of attachments affects whether an attachment link will have an expiration date.
- Links to public attachments do not expire.
- Non-public attachments have a lifetime of 1 hour by default from the moment they are generated. The lifetime of a link is determined through the system property s3.presigned.link.lifetime.
The Public attribute on the Attachment form defines the publicity of attachments.
To generate attachment links, log in and use the relative link /attachments/${sys_attachment.sys_id} to download attachments. You can also use the getAttachmentUrlById(attachmentId) method to generate a link via the API. See the SimpleAttachments article to learn more.
Depending on the publicity of an attachment, two links can be generated. For example:
- for non-public attachments: https://s3-{your-instance-url}/attachment/9/b7/prp5bikeyg70mpn7mhfszi4amgzleo?response-content-disposition=inline%3B%20filename%3D%22image.png...
- for public attachments: https://s3-{your-instance-url}/public-attachment/9/b7/prp5bikeyg70mpn7mhfszi4amgzleo?response-content-disposition=inline%3B%20filename%3D%22image.png...
- No labels