Scripted Rest Api - Base 64 or binary conversion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2025 12:00 AM
I have attachments up to 30 MB in size that I need to send to a third-party system. I've created a Scripted REST API that uses base64 encoding to convert the files, but it only works for files up to 2 MB. For files exceeding 5 MB, the conversion fails. Is there any approach to migrate these files to the third-party system?
We tested the out-of-the-box Attachment API and received a response like the following. How can a third party convert that response into a file and attach it to their system (for example, Workday)?
Give me solution for this requirement!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2025 05:47 AM
then this will work for more 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);
-> the maximum attachment size that the system will return for base64 encoding for is controlled by this system property "com.glide.attachment.max_get_size".
-> If the property does not exist it will default to maximum 5 MB.
-> If that property is not there then create it and set the value as per your need.
However, as mentioned in the following KB, this may cause some issues.
Large attachments may cause Out Of Memory errors and performance degradation
OR
Another way is to use GlideScriptableInputStream and GlideTextReader
This is the video for the same
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2025 03:54 AM
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
