Downloading and writing a base64 encoded ZIP file

Hello,
Has anyone had experience of downloading a base64 encoded ZIP file. It sounds relatively straight forward however the file that is created cannot be opened (m/s invalid file format error appears). The size of the file is almost the same as the source file, therefore I assume somewhere the process is going wrong.

Any help appreciated!

In your pipeline, is the SOAPExecute snap outputting a byte array or a string that is base64?

Also, what is the MultipartWriter doing in this pipeline?

The SOAP response will detail the file name, date and the file split into chunks of data (base 64 binary).

jsonPath(, "[‘soap:Body’].Stream_LatestPackageResponse.Stream_LatestPackageResult.File.Chunk")

We’re building an array of the encoded strings. See the splitvalue screenshot.

The intention of the multipart writer was to merge the individual binary output and write the zip file

Anyone any ideas?

Instead of doing a split, you’ll want to decode the base64 strings with Base64.decodeAsBinary() to turn them into byte arrays. You can then combine them using the Uint8Array.concat() method (which is not documented at the moment, we’ll get that fixed). The concat() method will concatenate byte arrays and return a new byte array. The following expression puts it all together:

Uint8Array.of().concat(...$[‘soap:Body’].Stream_LatestPackageResponse.Stream_LatestPackageResult.File.Chunk.map(Base64.decodeAsBinary))

Note: the concat() is a method on an existing byte array, so the above expression first creates an empty byte array with Uint8Array.of() so that we can pass all of the byte arrays using the spread operator (...).

Here’s a pipeline that demonstrates this stuff:

concat-bits_2019_12_02.slp (5.6 KB)

The MultipartWriter snap is for writing a MIME Multipart message, which is not what you are looking for here.

1 Like

Thank you, that’s resolved it. Works perfectly.