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

Downloading and writing a base64 encoded ZIP file

fbatchelor83
New Contributor

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.

image

Any help appreciated!

7 REPLIES 7

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.

fbatchelor83
New Contributor

Anyone any ideas?

fbatchelor83
New Contributor

Thank you, thatโ€™s resolved it. Works perfectly.