Using the Faraday Ruby Gem to Upload Images and Burn

When using the Faraday gem, hit the URL for the image as follows:

http_conn = Faraday.new do |builder| builder.adapter Faraday.default_adapter end response = http_conn.get 'http://example.tld/image.png' 

How can you write an image file from Faraday's answer to disk?

Debugging the response.body attribute shows that this is binary data.

Any help is greatly appreciated.

+8
ruby file io binary download
source share
1 answer

Why just write response.body like any other file?

 File.open('image.png', 'wb') { |fp| fp.write(response.body) } 
+11
source share

All Articles