How to zip binary attachment in scoped app?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2015 06:03 PM
As we convert our app we need to find alternative to zip file attachments. We use it to send large files for processing outside ServiceNow via REST API
This is a function we used:
var sa = new GlideSysAttachment();
var binData = sa.getBytes(gr);
var zipBinData = this.addBytesToZip(gr.file_name, binData);
encData = GlideStringUtil.base64Encode(zipBinData);
//put it into Json
//send via REST Message
addBytesToZip: function(fileName, stream) {
var outStream = Packages.java.io.ByteArrayOutputStream();
var out = new Packages.java.util.zip.ZipOutputStream(outStream);
out.putNextEntry(new Packages.java.util.zip.ZipEntry(fileName));
out.write(stream, 0, stream.length);
out.closeEntry();
out.close();
return outStream.toByteArray();
},
Obviously, packages are no longer supported. Is there another or better way?
Thx!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2015 01:31 PM
Alexey,
We put in a request to implement a proper export set API, but this will not help you in the near future.
When Fuji FP2 releases you will have access to a couple methods that may make this possible without the zipping.
You can try the following on FP2:
var sa = new GlideSysAttachment();
var binData = sa.getContent(gr); /* getContent is limited to 5mb */
encData = gs.base64Encode(binData);
//put it into Json
//send via REST Message
Please feel free to email me if you have further questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2015 04:01 PM
All right, finally made it working. Basically, due to memory limitations of GlideSysAttachment and our need to be able to upload large files to our server we decided to refactor the solution. Now our server pulls attachments directly from SN. We tried using processor approach (by gluing together sys_attachment_doc fragments) first, but it didn't work as we could not receive a well-former gzip stream in processor.
So the solution was to use sys_attachment.do?sys_id=... request from our server (previously authenticating to SN login.do). Worked like a charm.
That let us get rid of attachment management at all.
Thank you Bobby for your great support!