Ian morgan
Ian morgan

Reputation: 945

Ruby - Copy image from different server

I am using an api that has a list of images that I would like to save to my own server. Does anyone have any suggestions on what are the best ways of doing this? or what lib's I should be looking to use?

Thanks, Ian

Upvotes: 1

Views: 580

Answers (2)

ngoozeff
ngoozeff

Reputation: 4746

Ruby's open-uri library is a quick way to get going.

open-uri

It extends the open method with support for urls, so the following works:

require 'open-uri'

File.open("out.png", "w") {|o|
  open("http://www.example.com/some.png") {|f|
    o.write( f.read )
   }
}

Upvotes: 6

Related Questions