How get pdf file from httparty get response

617 Views Asked by At

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

1

There are 1 best solutions below

0
Yurii Stefaniuk On BEST ANSWER

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