How to send data as base64 more than 5Mb

Daniel Biesiada
Mega Guru

Hi, I need more knowledge about integration I have script which encode attachment as base64 everything was fine but I need to send Attachments bigger than 5Mb so I came up with idea to use: 

var toBody = new GlideRecord('sys_attachment');
            toBody.get(att.u_document);// att sys_id

var StringUtil = new GlideStringUtil();
            var atts = new GlideSysAttachmentInputStream(toBody.sys_id+'');
            var baos = new Packages.java.io.ByteArrayOutputStream();
            atts.writeTo(baos);
            var bytes = baos.toByteArray();
            baos.close();
            var encData = StringUtil.base64Encode(bytes);
            obj.body = encData;

After that script I'm configuring REST message with:
    r.setStringParameterNoEscape('key' encData); 
after execute I got socket error and status code 0. Any idea how to solve this? 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Did you try to print log and check encData variable?

check these links:

https://community.servicenow.com/community?id=community_question&sys_id=6d6f7aaddbad4010d58ea345ca96...

https://community.servicenow.com/community?id=community_question&sys_id=30efbeaddb58dbc01dcaf3231f96...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi, 
Of course I did problem exist with big files they are encoded correctly but when I'm trying to execute request I got status code 0 and no response body.

Hi,

Probably it means 3rd party is not able to handle the large base64encoded data.

Are you sure the key parameter holds the base64 data?

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yes, I'm sure .rtf file which is about 40Mb so it end up as 40B characters maybe I can split it in several files.