开发者

Best way to download and process images during user data import feature?

I have a feature where users bulk import data via CSV. The CSV can have image URLs nested in it.开发者_StackOverflow How can I grab the images via the given URLs and post them to my site?

I'm using Ruby 1.9.2, Rails 3, Paperclip w/ S3 as my backend.

Thanks for reading and possibly helping!


I assume you already have all the logic to parse the CSV and get the URL (if not, look into either csv in the standard library or FasterCSV). To grab the file you could:

  • Use Net::HTTP (see this page)
  • Use open-uri (which I guess is really just a wrapper for Net::HTTP, but I prefer the syntax (see this question))
  • Call off to wget or curl to grab the file for you (see this question if calling command line programs from Ruby is a question)

After that, I suppose it's simply a matter of putting a tag on a page and pointing to wherever you saved the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜