Rest API attachment file size issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2017 07:12 AM
Hi
We are working on Incident Ebonding. As part of that we have to push the attachment for another service- now instance. We have to use rest API for the integration. The attachment is getting transferred however the file more than 4 MB is not getting transferred. tried the same code with SOAP API and it worked fine without any size limitations.
I am pasting the code below. Please let us know if for REST API we need to use any other encoding method.
var target = new GlideRecord('sys_attachment');
target.addQuery('table_name', 'incident');
target.addQuery('table_sys_id', current.sys_id);
target.query();
while(target.next()) {
var sa = new GlideSysAttachment();
var binData = sa.getBytes(target);
var base64Data = GlideStringUtil.base64Encode(binData);
var file_name = target.getDisplayValue();
var name =target.getDisplayValue();
var attachmentlable = target.getValue('file_name');
var content_type = target.getValue('content_type');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 12:07 AM
Default max size for attachments in REST is 1GB. Have you checked if the property was not modified?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2019 03:06 AM
getBytes() Method has 5 MB Restriction. You need to use SysAttachmentInputStream and read bytes from it.
var gsa = GlideSysAttachmentInputStream(attachmentGR.sys_id.toString());
var baos = new Packages.java.io.ByteArrayOutputStream();
gsa.writeTo(baos);
baos.close();
var base64Data = GlideStringUtil.base64Encode(baos.toByteArray());