11-04-2021 03:07 AM
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.
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
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!
Solved! Go to Solution.
11-04-2021 07:17 PM
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!
11-04-2021 09:27 AM
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.
11-04-2021 07:17 PM
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!
11-05-2021 08:55 AM
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.
11-06-2021 09:38 PM
Hi @ptaylor ,
Thank you so much. That actually helps a lot!
11-04-2021 08:55 AM
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.