Maximum file size to convert to base64 in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2020 04:25 AM
What is the Maximum file size to convert to base64 in servicenow? i tried with 2MB and 3MB but it is not converting to base64. Please help me in this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2020 05:57 AM
Yes, am getting the output for bytes and size ,
var content64 = GlideStringUtil.base64Encode(bytes);
the above line am getting emptyoutput .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2020 06:49 AM
I have one question. The file am using is PDF which has images in the pdf so, is that the problem for not converting base64?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2020 06:59 AM
Hi Ramesh,
That should not be an issue
can you update code as below
var StringUtil = new GlideStringUtil();
var content64 = StringUtil.base64Encode(bytes);
gs.info(content64);
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
02-04-2020 07:10 AM
Yes, I updated but still same issue. Not getting output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2020 07:26 PM
Hi Ramesh,
This script works for me in Global scope for both files under 5MB and greater than 5MB
var gr = new GlideRecord('sys_attachment');
gr.get('d7ff2c044f96cc90fc11fa218110c746');
var StringUtil = new GlideStringUtil();
var gsis = GlideSysAttachmentInputStream(gr.sys_id.toString());
var ba = new Packages.java.io.ByteArrayOutputStream();
gsis.writeTo(ba,0,0);
ba.close();
var base64EncodedData = StringUtil.base64Encode(ba.toByteArray());
gs.info(base64EncodedData);
Try running this in scheduled job and print in logs; if you try running in scripts
background the instance may get timeout since it is huge data to print
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