{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":427,"path":"api-reference/rest-api-explorer/r_ScriptedRESTExampleStreamAttach.md","title":"Scripted REST API example - streaming file attachments","bundle":null,"doc_type":null,"release":"australia","body":"\n# Scripted REST API example - streaming file attachments\n\nThis example demonstrates how to send an image attachment to a requesting user as a binary stream.\n\n```\n/**\n *  Sample Scripted REST Resource that returns a stream of binary representing an attachment\n *  This sample uses ServiceNow JavaScript API GlideSysAttachmentInputStream to get an attachment as a stream then\n *  users WriteStream to stream the response.\n */\n(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {\n    var hdrs = {},\n        attachment_sys_id = '1852fd52471321009db4b5b08b9a71a9';\n\n    hdrs['Content-Type'] = 'image/jpeg';\n    response.setStatus(200);\n    response.setHeaders(hdrs);\n\n    var writer = response.getStreamWriter();\n    var attachmentStream = new GlideSysAttachmentInputStream(attachment_sys_id);\n    writer.writeStream(attachmentStream);\n})(request, response);\n```\n\nA request to this resource returns the following response.\n\n```\n//  sample response\n/*\n HTTP/1.1 200 OK\n Set-Cookie: glide_session_store=SYSTEM; Expires=Fri, 30-Oct-2015 21:57:00 GMT; Path=/; HttpOnly\n Content-Type: image/jpeg\n Transfer-Encoding: chunked\n Date: Fri, 30 Oct 2015 21:26:59 GMT\n Connection: close\n Server: ServiceNow\n\n <binary response body excluded from this sample>\n */\n```\n\n**Parent Topic:**[Scripted REST API examples](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-api-explorer/c_ScriptedRESTAPIExamples.md)\n\n"}}