Combine all the attachments to a ZIP File - REST API

Mahesh Murikip1
Tera Contributor

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