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

Downloading a base64 zip file using SOAP

tonyzero
New Contributor II

Hi All,

I am trying to use SOAP call to download a zip file. However, I cannot download and get the file I need correctly. Here is a screenshot of my pipeline.
Capture

I took out the $content, which contains a string that is (at least looks like) base64 encoded data. The โ€œContent-Typeโ€ is null and โ€œContent-Transfer-Encodingโ€ is
โ€œbinaryโ€.

Then no matter how I decode this string, whether by using Base64.decode() or Base64.decodeAsBinary(), I cannot get the zip file I need. If I use Base64.decode($content), I get something like
Capture1

I can see my file name within a bunch of words that I cannot read. And I think I should not use Base64.decodeAsBinary().

Could someone please tell me what is the correct way to download this zip?

Thanks in advance!

1 ACCEPTED SOLUTION

tonyzero
New Contributor II

Hi @ptaylor ,

I followed you suggestion and it really works. I used Base64.decodeAsBinary($content) together with application/zip โ†’ $[โ€˜content-typeโ€™] and got the txt file in a zip.
However, I am still not sure why I should use Base64.decodeAsBinary() to decode something what really looks like a base64 encoded string.

Thank you very much!

View solution in original post

10 REPLIES 10

Iโ€™m a bit confused by the SOAP Execute response. Itโ€™s reporting the Content-Transfer-Encoding as โ€œbinaryโ€, which essentially means โ€œnot encodedโ€. The actual content โ€œUEsDBBQAโ€ฆโ€ looks like it actually is base64-encoded. If so, try this:

In your Mapper, change the expression to Base64.decodeAsBinary($content). Then in the Views tab of the Mapper settings, modify the output viewโ€™s type from Document to Binary. Attach a File Writer to write the content to a .zip file.

tonyzero
New Contributor II

Hi @ptaylor ,

I followed you suggestion and it really works. I used Base64.decodeAsBinary($content) together with application/zip โ†’ $[โ€˜content-typeโ€™] and got the txt file in a zip.
However, I am still not sure why I should use Base64.decodeAsBinary() to decode something what really looks like a base64 encoded string.

Thank you very much!

Great!

Base64.decodeAsBinary() is the fundamental function: converting a base64-encoded String to a byte array containing the binary data (in this case, the zip compressed data).

Baes64.decode() is actually a compound function: it starts by calling decodeAsBinary to convert the base64 String to a byte array, then converts that byte array to a String using the UTF-8 charset. In this case, the data in the byte array isnโ€™t a UTF-8-encoded string, so that second conversion is just wrong and doesnโ€™t result in anything meaningful. You need to first decompress the data in the byte array before converting it back to text.

Hope that helps.

tonyzero
New Contributor II

Hi @ptaylor ,

Thank you so much. That actually helps a lot!

j_angelevski
Contributor III

Hi @tonyzero,

I donโ€™t think you should decode the content like that, as far as I understood, you are getting the .zip file from the SOAP endpoint, which returns binary data, then what you should really do is just map the $content of the SOAP as $content, you shouldnโ€™t decode anything in the mapper. Also, your $['content_type'] target path is not valid, you should write $['content-type'] not $['content_type'] with an underscore.