Rest API attachment file size issue

vikarantkmr
Kilo Explorer

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');

2 REPLIES 2

sergiu_panaite
ServiceNow Employee

Default max size for attachments in REST is 1GB. Have you checked if the property was not modified?



Attachment API


Taksh
ServiceNow Employee

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());