Trying to return a binary tar file as the response.content

pdouglas
Participant III

Our objective is to hit an endpoint to download a tar.gz to disk with pre-determined filename. The catch we have is trying to decode the binary string into a valid archive. We've tried a Python policy (base64decode) as well as @Dino-at-Google's online sample, but we are missing something. When done within Apigee, decoding the text will not be a valid archive. In Dino's POC we can decode our string but need to open the response file, remove the top 5-6 lines including headers, date/time and response code then save with tar.gz extension and it is a valid archive. We've tried removing headers using Dino's included Assign Message policy however it doesn't work for all headers. I have included a sample json we get from the backend ("binary" is the base64-encoded tar.gz and filename). Thank you! binarylog.txt (download and change extension to json)

Solved Solved
0 4 1,033
1 ACCEPTED SOLUTION

ok I understand

Just looking at your curl command, you are using -i, which tells curl to ... emit the headers it receives in response. Are those the 5 lines you are removing?

If that's the case, then you may be able to avoid the problem by omitting the -i from the curl command line. Can you try that and let me know?

View solution in original post

4 REPLIES 4

The catch we have is trying to decode the binary string into a valid archive.

when? where? Within Apigee?

I see your json file.

{
  "binary": "H4sIAAAAAAA...embVxwAuAAA=",
  "filename": "syslog.tar.gz"
}

Is that the payload that the backend target delivers to Apigee?

If so, What do you want your Apigee proxy to do with that?

Also I don't understand this part of what you wrote:

In Dino's POC we can decode our string but need to open the response file, remove the top 5-6 lines including headers, date/time and response code then save with tar.gz extension and it is a valid archive. We've tried removing headers using Dino's included Assign Message policy however it doesn't work for all headers.

Apologies, many thanks for responding.

Yes the included file above is a sample payload from our target. We aim to base64-decode the “binary” portion of the json into a filename of “filename.”

We used the ApigeeEdge-Java-Simple-Base64 GitHub repo to make a POC to decode the binary data. Here is a sample curl:

curl -i -X POST https://dev-api.blabla.com/base64-encoder/t2?action=decode -H "content-type:application/gzip" -d "@/Users/blablaUser/sysout.bin" > Sysoutbin_decoded.tar.gz

I also zipped and attached the in (sysout.bin) file and out (Sysoutbin_decoded.tar.gz) file used in the curl. With the output file, if we remove the top 5 lines it can be saved as a valid archive/tar.gz and then be opened with a zip utility. Also included, codesnippet.txt shows the Python pattern the backend developers are using to accomplish what we are trying to do here.

Thanks again, Dino!

archive.zip

ok I understand

Just looking at your curl command, you are using -i, which tells curl to ... emit the headers it receives in response. Are those the 5 lines you are removing?

If that's the case, then you may be able to avoid the problem by omitting the -i from the curl command line. Can you try that and let me know?

Jackpot - I'm embarrassed it was that simple but also happy we can implement using this library in our proxy. MANY, many thanks Dino! I'll post here later (next week) once we've completed the task in our proxy.