- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2019 10:19 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2019 01:45 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2019 01:45 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2019 01:04 PM
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().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2019 05:00 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 02:40 AM
Hi,
Did you try sending larger files more than 24Mb.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader