Return binary file from scripted rest api

Drct1234
Mega Expert

Hello,

Is there a way to return a binary file as output from a scripted rest API?
The file is returned from another endpoint.
I want to achieve something similar to what GlideSysAttachment().getContentStream(sys_id) and response.getStreamWrite allow.
In this case, the source file is the response from a RESTMessageV2 GET call.
I can't find a way to set the response body from the binary content.

Thanks!

1 ACCEPTED SOLUTION
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Drct1234 

check below link should help you

Download file using REST API

Regards
Ankur

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

Thanks Ankur,
I need the file to be returned from a SNOW scripted REST API. I am getting the content  of the file using a RESTMessageV2 call (inside the SNOW script). I'm not using an external rest call like it's mentioned in the link you provided.

Hitoshi Ozawa
Giga Sage
Giga Sage

If the binary file is an attachment, I've posted Scripted REST API code to download the file in the following thread.

https://community.servicenow.com/community?id=community_question&sys_id=d321fd77dbab5810b1b102d5ca96...

EDIT: ServiceNow ended a way to zip files and download. This may be because zipping file is CPU and memory intensive so if many users do it at once, it may impact performance on an instance. However, it may be possible to zip the current attachments to create a new attachment file and then download that.