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

I am currently exploring the replacement of GlideEncrypter with GlideStringUtil.base64Decode in a script I am working on. The initial tests indicate that the replacement seems to function as expected. However, I want to ensure that this approach adheres to best practices and will not negatively impact the future performance or maintainability of our instance. Could you please confirm if this is a recommended practice, or if there are any potential concerns or alternative methods I should consider?

Hi Ankur,

This is not working for scoped application. Is there any way to do this in scoped app for files greater than 5 MB?

Hi Priya,

I doubt there exists anything for this currently in scoped app

Regards
Ankur

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

I know this answer is from years ago, however, I cannot find documentation of the method you are using. Can you please share link?

The files are being sent but unable to open with the above script