Tuesday, 27 August 2013

How to download an image file via HTTP into a temp file?

How to download an image file via HTTP into a temp file?

I've found good examples of NET::HTTP for downloading an image file, and
I've found good examples of creating a temp file. But I don't see how I
can use these libraries together. I.e., how would the creation of the temp
file be worked into this code for downloading a binary file?
require 'net/http'
Net::HTTP.start("somedomain.net/") do |http|
resp = http.get("/flv/sample/sample.flv")
open("sample.flv", "wb") do |file|
file.write(resp.body)
end
end
puts "Done."

No comments:

Post a Comment