How do I use the Multipart Writer to create a correct multipar form-data?
Here's a comprehensive guide on how to use the Multipart Writer Snap to create a correct multipart/form-data stream in SnapLogic: --- ๐ฆ Multipart Writer โ Overview The Multipart Writer is a Transform-type Snap that merges multiple binary documents into a single MIME multipart stream. It is typically used when you need to POST multiple files or binary data to a REST endpoint.
โ ๏ธ Note: The Multipart Writer does not support Ultra Pipelines.
--- ๐ง Key Configuration Fields | Field | Description | |---|---| | Label | A unique name for the Snap | | Binary Header Properties | Modify the binary output document header using expressions and target JSONPaths | | Group Identifier | Controls how many output documents are generated (one per group change) | | Snap Execution | Default is Execute only | --- ๐๏ธ How to Build a Multipart Form-Data Pipeline Step 1 โ Prepare Binary Input Connect one of the following upstream Snaps to feed binary data into the Multipart Writer: - File Reader โ reads files from SLDB or external file systems - Document to Binary โ converts document data to binary - XML Formatter โ formats XML as binary Step 2 โ Configure the Multipart Writer 1. Binary Header Properties (optional): - Use the Expression column to compute values to insert into the header. - Use the Target Path (JSONPath) to specify where the value should be written in the header. - Example target path: $['content-location'] 2. Group Identifier (optional): - Leave blank to produce a single multipart output containing all input documents. - Set to an expression (e.g., $num or $['content-type']) to produce multiple output documents, one per unique group value. - The Snap watches for changes in the identifier value โ when it changes, a new output document is started. Step 3 โ Send to a REST Endpoint Connect the Multipart Writer output to a downstream Snap such as: - HTTP Client (recommended) โ set Entity Type to multipart - REST Post - File Writer (for testing/debugging) --- ๐ Example: JSON Data โ Multipart Stream
JSON Generator โ Multipart Writer โ File Writer / HTTP Client
- The JSON Generator passes structured data to the Multipart Writer. - In the Multipart Writer, set the Group Identifier to $num (or any field) to split output into separate multipart documents per group. --- ๐ Example: File Upload via REST Client
File Reader โ Multipart Writer โ HTTP Client (POST)
- The File Reader reads binary files. - The Multipart Writer merges them into a multipart stream. - The HTTP Client POSTs the stream to the target endpoint. --- ๐ก Tips & Best Practices - Content-Type header: When using the HTTP Client downstream, do not manually set the Content-Type header to multipart/form-data. Let the Snap handle it automatically โ manually setting it can cause a 400 - Invalid boundary error. - File paths in SLDB: When referencing files dynamically, prefix paths with sldb:/// (e.g., sldb:///myfile.csv). - Group Identifier behavior: The Snap only detects changes in the identifier value โ it does not sort or group by value. Make sure your input is ordered correctly if grouping matters. - Binary input required: The Multipart Writer only accepts binary input views โ ensure upstream Snaps output binary data. --- ๐ Typical Input/Output | | Type | Description | |---|---|---| | Input | Binary | Binary documents to be merged | | Output | Binary | A single MIME multipart stream | | Error | Document | Error documents (0 or more) | --- Let me know if you'd like help building a specific pipeline using the Multipart Writer! ๐
