GlideStringUtil.base64Encode is not converting large files to base64encode string.

Palle
Tera Contributor

Hi SN community, 

We have a SOAP based integration with a third party system where we will be sending the large attachments >5mb through the webService call to the third party system. I am using GlideStringUtil.base64Encode to convert the attachments to base64encode string, any attachments >5MB are not getting converted to string. 

Is there any other way I can achieve converting large files to base64 encoded string?

Any suggestion/recommendations would be appreciated.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I think for more than 5mb file base64encoded data is difficult to get; try checking below script whether it works; gr is the gliderecord object of sys_attachment table

var StringUtil = new GlideStringUtil();

var gsis = GlideSysAttachmentInputStream(gr.sys_id.toString());

var ba = new Packages.java.io.ByteArrayOutputStream();

gsis.writeTo(ba);

baos.close();

var base64EncodedData = StringUtil.base64Encode(ba.toByteArray());

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

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I think for more than 5mb file base64encoded data is difficult to get; try checking below script whether it works; gr is the gliderecord object of sys_attachment table

var StringUtil = new GlideStringUtil();

var gsis = GlideSysAttachmentInputStream(gr.sys_id.toString());

var ba = new Packages.java.io.ByteArrayOutputStream();

gsis.writeTo(ba);

baos.close();

var base64EncodedData = StringUtil.base64Encode(ba.toByteArray());

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 Ankur, 

I think Packages.java.io.ByteArrayOurputStream() is not accessible on new york version. Below is how my code looks like. 

var gr = new GlideRecord('sys_attachment');
gr.addEncodedQuery('table_sys_id=' + xyz.sys_id);
gr.query();
while (gr.next()) {
var binData = GlideSysAttachmentInputStream(gr.sys_id.toString());
var Ka = new Packages.java.io.ByteArrayOutputStream();
binData.writeTo(Ka);
Ka.close();
var encData = GlideStringUtil.base64Encode(Ka.toByteArray());
this.addAttachment(encData, xyz.u_unique_id, gr.file_name + ' - ' + gr.content_type, gr.file_name, xyz.number);

 

addAttachment is the function(SOAP body) I use it to send the attachment to the third party system. I troubleshooted in the script debugger to see flow of script execution and it never executed after Packages.java.io.ByteArrayOutputStream().

 

Palle
Tera Contributor

Ankur,

Thank you for the above answer.

I have tried updating binData.writeTo(Ka) to binData.writeTo(Ka,0,0); and also update the value of the below 2 properties:

1. glide.size.aware.max_size.org.mozilla.javascript.NativeString----->320000000

2. glide.size.aware.max_size.java.lang.String ----> 320000000

 I can successfully send the files up to 20mb. I am looking for something to achieve up to 24Mb. How can I achieve it?

Is there any possibility of breaking the Java package when we do version upgrades in the future? Is it best practice? 

 

Hi,

Did you try sending larger files more than 24Mb.

Regards

Ankur

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