Combine all the attachments to a ZIP File - REST API
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 07:36 AM
I have created a custom API. But not sure, how to zip all the files together. I believe that I am missing something here. Any insights or suggestions will help me out.
var queryParams = request.queryParams;
var recordSysId = queryParams.sysparm_sys_id.toString();
var tableName = queryParams.sysparm_table.toString();
var gr = new GlideRecord(tableName);
if (gr.get(recordSysId)) {
//fileName = gr.number.toString() + '.zip';
var attachmentSysId = new GlideRecord('sys_attachment');
attachmentSysId.addQuery('table_sys_id', gr.sys_id);
attachmentSysId.addQuery('table_name', gr.getTableName());
attachmentSysId.query();
while (attachmentSysId.next()) {
var hdrs = {};
hdrs['Content-Type'] = attachmentSysId.content_type.toString();
hdrs['Content-Disposition'] = attachmentSysId.file_name + ";filename*=UTF-8''" + attachmentSysId.file_name;
response.setHeaders(hdrs);
var writer = response.getStreamWriter();
var attachmentStream = new GlideSysAttachmentInputStream(attachmentSysId.sys_id);
writer.writeStream(attachmentStream);
}
}
0 REPLIES 0