I am sending an HTTP GET request to a third-party API that responds with binary content (a pdf document). I would like to use the response body as a paperclip attachment.
Using the Faraday gem to make the HTTP GET request, I can see the following output from the server:
pragma: "no-cache"
content-length: "16080"
content-type: "application/octet-stream"
expires: "-1"
server: "Microsoft-IIS/8.5"
content-disposition: "attachment; filename=2160506180802980077.pdf"
x-aspnet-version: "4.0.30319"
set-cookie: "XDEBUG=; path=/"
p3p: "CP=\"NOI OUR PSA DEV PSD STA COM CUR\""
date: "Sun, 08 May 2016 03:38:41 GMT"
connection: "close"
The code fails with the following error:
Paperclip::AdapterRegistry::NoHandlerError: No handler found for 16080
It looks like somehow Paperclip is reading the content-length as the content-type.
I’m looking for some help either to resolve the issue above, or propose an alternative method to read an octect-stream from an HTTP GET response in as a Paperclip attachment.
download_document returns a String. When I inspect the returned object, it appears to be a binary representation of the PDF document (see below). Do I have to encode this somehow before writing it to a file?