โ05-11-2018 06:49 AM
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.)
โ05-11-2018 07:35 AM
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:
Base64.decodeAsBinary($content)
$['content-type']
Hereโs a screenshot of what was received by putsreq.com:
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)
โ05-11-2018 08:08 AM
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?
โ05-11-2018 08:10 AM
It was basically the same pipeline where the output of the MultipartWriter was connected to a FileWriter.