- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 08:33 AM
Hi Experts,
Recently I have developed a scripted REST API for one of our customer. This API sends a response to the Document Requests made on the customers third party portal, the response contains base64 of files that are requested.
Sending files upto 10MB does not create a problem, however when file size exceeds 10MB HTTP error code 500 is returned as response.
As suggested by some of the community posts and knowledge articles, I created following system properties to surpass this limit, but it did not work.
1) glide.rest.max_content_length
2) glide.http.outbound.max_timeout
Below is the script I have used to encode the file-
var StringUtil = new GlideStringUtil();
var gsis = GlideSysAttachmentInputStream(SYS_ID OF ATTACHMENT RECORD);
var ba = new Packages.java.io.ByteArrayOutputStream();
gsis.writeTo(ba, 0, 0);
documentObj.base64EncodedData = StringUtil.base64Encode(ba.toByteArray());
documentObj.fileName = documentAttachment.file_name.toString();
documentObj.fileType = documentAttachment.content_type.toString();
var size_bytes = parseInt(documentAttachment.size_bytes);
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var MB = (size_bytes / Math.pow(1024, 2)).toFixed(2) * 1 + ' ' + sizes[2];
documentObj.documentSize = MB;
}
}
var parser = new JSON();
var str = parser.encode(documentObj);
return str;
If I run this function in background script, following error is encountered-
I would like to ask few questions in this context-
Question 1: Is it a restriction from REST that I am not able to send large files? Or it is because of the String Object size that is getting exceeded?
Question 2: Is there a way by which File getting sent can be compressed under 10 MB and sent? I tried to compress a PDF file of 18MB manually but its size got reduced to 15MB only, so not sure compression would work.
Question 3: Can the file be broken into small chunks and then encoded and sent back as response? If yes, please let me know the script that would help.
Question 4: Is there any other way to achieve this requirement?
Thank you for reading this post. Please provide your inputs at the earliest.
Thank you
Astha Chaubey
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 09:21 AM
Hi,
yes there is a limit
increase the system property
glide.size.aware.max_size.org.mozilla.javascript.NativeString -> 83886080
Regards
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
03-26-2025 07:30 AM
There is no such system property in the ServiceNow instance. Can you please help?