Forum Discussion

Regina's avatar
Regina
New Contributor II
7 years ago
Solved

Using REST GET to read zip output

Hello All,

I have a requirement where I am getting a response from a REST GET as a ZIP file.
REST GET snap returns error when it tries to read ZIP output. Please see screenshots below. Can you please let me know what should be done to allow REST Get to process ZIP output? Any help to solve this issue would be highly appreciated.

Thank you!

Regina K.



  • The error is due to the REST snap trying to interpret the response as JSON. You’ll need to change the ‘Response entity type’ option to ‘BINARY’ to get the snap to work. However, once that is done, you’ll need to jump through a couple of hoops to get the zip unpacked. It turns out the ZipFileRead snap can only read from a file, so you’ll need to write out the binary from the REST snap. To write out the binary data, you can use a DocumentToBinary snap to turn the document into a binary document and then a FileWriter that writes to the pipeline temporary directory. Finally, the ZipFileRead snap can read that file and you can do stuff after that.

    I’m attaching the example pipeline as well:

    RestGetZip_2019_02_05.slp (9.1 KB)

2 Replies

  • tstack's avatar
    tstack
    Former Employee

    The error is due to the REST snap trying to interpret the response as JSON. You’ll need to change the ‘Response entity type’ option to ‘BINARY’ to get the snap to work. However, once that is done, you’ll need to jump through a couple of hoops to get the zip unpacked. It turns out the ZipFileRead snap can only read from a file, so you’ll need to write out the binary from the REST snap. To write out the binary data, you can use a DocumentToBinary snap to turn the document into a binary document and then a FileWriter that writes to the pipeline temporary directory. Finally, the ZipFileRead snap can read that file and you can do stuff after that.

    I’m attaching the example pipeline as well:

    RestGetZip_2019_02_05.slp (9.1 KB)

    • Regina's avatar
      Regina
      New Contributor II

      Thank you for detailed info. It helped a lot! Regina