Multipart HTTP POST

A bit related to THIS other topic:

But any good solutions for constructing and posting a multipart-mime message to a remote HTTP server?

I have use cases where I want to take several “fields” along with a “file” and post it as a single multipart-mime message to a partner’s HTTP server. With the Rest Post snap, you can post a single file with a specified name as a multipart message (but only with that one “part”). I also see there seem to be some new Multipart Reader and Multipart Writer snaps that you can use to deconstruct or construct a multipart file with separate parts and boundaries and such, but you can’t really POST that to a HTTP server… If you save off a constructed multipart file and try to post it with a Rest Post snap, it will try to wrap and treat the whole thing as a single file/part like mentioned above. If you try to post it to a URL with the File Writer snap, then it will post the file, but without the “headers” (which define the boundaries, etc.)

I didn’t try this with a real server, only with, but both options seemed to send the right data. The problem with the FileWriter is that it sends a PUT, not a POST. For the REST Post version, I used BinaryToDocument to convert the output of the MultipartWriter to a document configured the REST Post as follows:

  • Upload body type – “Binary”
  • Entity – Base64.decodeAsBinary($content)
  • HTTP Headers – Content-Type | $['content-type']

Here’s a screenshot of what was received by

That seems right, but there might be something I’m missing. The FileWriter version seemed right as well, there was a Content-Type header with the boundary that matched what was in the body.

I’m attaching the REST Post version of the pipeline, which reads the CSV files from an SLFS directory and combines them with a MultipartWriter:

MultipartPost_2018_05_11.slp (7.0 KB)

Thanks, I’ll check it out! My files might be quite large (1GB), so I’m a little nervous about the encode/decode. Do you have your FileWriter example too?

It was basically the same pipeline where the output of the MultipartWriter was connected to a FileWriter.