cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Multipart HTTP POST

christwr
Contributor III

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.)

3 REPLIES 3

tstack
Former Employee

I didnโ€™t try this with a real server, only with https://putsreq.com/, 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 putsreq.com:

image

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)

christwr
Contributor III

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.