How can I upload binary files?
· One min read
Prior to version 3.1.0 of opscotch, you could only receive text content from the HTTP trigger i.e. json or text like. Version 3.1.0 now lets workflows receive raw binary uploads. The new context.getStream() call gives you direct access to the byte stream.
- Send a single HTTP request with
Content-Type: application/octet-stream. - The payload is exposed in the workflow as
context.getStream(), which returns aByteReader. context.getBody()is not involved here; stick togetStream()for binaries.- See the docs: /docs/next/apireference#JavascriptContext-getStream.
- See the companion post on
ByteReaderand buffer handling in Byte manipulation in workflows for how to read streams. - Also see How can I process multipart HTTP uploads in workflows? if you need to send metadata plus the file together.
How to send a binary upload
Here is an example curl command to upload a binary file:
curl "http://localhost:11000/upload" \
-X POST \
-H "Content-Type: application/octet-stream" \
--binary-data '@a-binary-file'
In your workflow JavaScript processor:
let stream = context.getStream(); // ByteReader for the uploaded bytes
.. // continue processing the stream.