- 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-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-18-2021 10:11 AM
Thank you for marking my response as helpful.
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
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-18-2021 10:12 AM
Hi Ankur,
Thank you for a quick response, that solved my problem of that string error and also I am not getting HTTP error code 500.
Just want to check with you, I am trying to send a file of 15MB in response, and I am initiating the request using Postman, I am getting an HTTP code 200 and it is taking around 20 secs for the response body to load, but even after the response body is displayed the page is not responsive for atleast 30mins, I had to cancel the transaction to bring the browser to normal state.
Is this the expected behavior because of the file size? Do you know how can I make this transaction quicker and the page responsive?
Thank you so much for your help!
Astha Chaubey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2021 10:18 AM
Hi,
yes there is some limit for inbound for Scripted REST API
please check this
Controlling maximum request size
that should be fine since the file size is huge
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader