Read Attachment
Use a Read Attachment node in your Flow to retrieve the content of a specific attachment by its ID. The node can output the file data as a stream, buffer, arraybuffer, or string. To configure a Read Attachment node in the Flow Editor, drag it from the Palette to the Workspace canvas, then double-click the node to open and configure its behavior.
Example of settings for a Read Attachment node
Select a Type Id for the node — the Object Type that has Records with which you want to use attachments, specified using one of several options.
type - choose this option for a dropdown that includes the Display Names of the Object Types you have created in your Contextual tenant.
string - choose the string option, and type in a string for the Object Type ID, using type is recommended instead of string
msg. - choose this option to specify a path in the msg. object that contains the Object Type ID value
env variable - Environmental Variables are a feature of Agents in Contextual. Any Environmental Variables that you define as Label/Value pairs for an Agent that is sending events to a Flow, will be available to the Flow, simply type the Label of the Environmental Variable from which you want to use the value.
Choose an Output Type to control how the attachment content is represented.
stream — default; a readable stream, suitable for piping directly into an HTTP response
buffer — a Node.js Buffer containing the full file contents in memory
arraybuffer — an ArrayBuffer, useful when passing content to browser-compatible APIs
string — the content decoded as a UTF-8 string, suitable for text-based formats
When the Read Attachment node is included in the path of your flow, it will retrieve the binary content of the specified attachment and place it in the configured output property.
Serving Attachment Content Over HTTP
When serving attachment content directly from an HTTP agent, use a Function node after Read Attachment to set the appropriate response headers before passing the message to an HTTP Response node.
// Function node — set response headers for inline file serving
const contentType = msg.req.query.contentType
const filename = msg.req.query.filename
msg.headers = {
"Content-Type": contentType,
"Content-Disposition": 'inline; filename="' + filename + '"',
"Cache-Control": "no-store"
}
msg.statusCode = 200
return msgIn this pattern, the caller passes contentType and filename as query parameters so the browser knows how to handle the returned binary content. Adjust the Content-Disposition value to attachment instead of inline if you want the browser to prompt a download rather than display the file in place.
Last updated
Was this helpful?