Home > database >  How get pdf file from httparty get response
How get pdf file from httparty get response

Time:06-11

I would like render a PDF with wicked_pdf or download it from GET response with httparty,

I succeed to do it with curl -o filename url but i dont know how do it with Rails

CodePudding user response:

You can do it like this:

filename = "tmp/test.pdf"
File.open(filename, "w") do |file|
  file.binmode
  HTTParty.get(URL_TO_PDF, stream_body: true) do |fragment|
    file.write(fragment)
  end
end

Replace URL_TO_PDF with your pdf url

  • Related