RESTAPIResponseStream - writeStream(Object stream)

Write an input stream to the response stream.

You must set the content type and status code before calling the writeStream() method or the response will fail. You cannot modify these values after calling the writeStream() method.

Table 1. Parameters
Name Type Description
stream Object An attachment or a response stream from a third-party service.
Table 2. Returns
Type Description
void

It is the responsibility of the script author to obtain the stream from a third-party service.

response.setContentType('application/json');
response.setStatus(200);
var writer = response.getStreamWriter();
var attachmentStream = new GlideSysAttachmentInputStream(<sys id of attachment>);
writer.writeStream(attachmentStream);