Can a file more than 10 MB be sent via REST API as response?

astha_chaubey
Tera Expert

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-

find_real_file.png

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

@Pradeep Sharma @Alikutty Abdulrazak @Chuck Tomasi @Palash Mahajan 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

yes there is a limit

increase the system property

glide.size.aware.max_size.org.mozilla.javascript.NativeString -> 83886080

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Hi @Ankur Bawiskar 

 

There is no such system property in the ServiceNow instance. Can you please help?