Handle application/pdf response as File with ruby

Correspondence when the response of the external API is application/pdf


response = http_client.get url
response.headers
# {
#  "content-type"=>"application/pdf",
# }

#If you write it simply, it's ok
file = ::File.open("path/to/pdf", "wb") do |f|
  f.write resp.body
  f
end

# AWS::S3.upload file.path
#Like
$ file path/to/pdf
# path/to/pdf: PDF document, version 1.4

Recommended Posts

Handle application/pdf response as File with ruby
[Ruby] Handle instance variables with instance methods
Handle DatePicker with Ruby / gtk3 + glade3
Read environment variables with ruby ​​file [Super beginner]
Install Ruby 3.0.0 with asdf
Handle files with NIO.2.
Handle devise with Rails
Handle JSON with minimal-json
Getting Started with Ruby
11th, Classification with Ruby
Evolve Eevee with Ruby
How to request a CSV file as JSON with jMeter
[Easy] How to automatically format Ruby erb file with vsCode