When using the Faraday gem to hit a URL for an image like this:
http_conn = Faraday.new do |builder|
builder.adapter Faraday.default_adapter
end
response = ht开发者_如何学JAVAtp_conn.get 'http://example.tld/image.png'
How can you write the image file from the Faraday response to disk?
Debugging the response.body
attribute shows it is binary data.
Any help greatly appreciated.
Why not just write the response.body
like any other file?
File.open('image.png', 'wb') { |fp| fp.write(response.body) }
精彩评论