简体   繁体   中英

Rails 3 + Paperclip + Amazon S3 + Download All Images

Background

  • I have been running a rails 3.XX app for 2+ years on Heroku.
  • User-uploaded images are stored in an Amazon S3 bucket via Paperclip.

What I Need

  • I want to download all images that have been uploaded (around 5000 images total) to a local disk.
  • I'd like to reduce the cost required to perform this query.

Problem

  • My knowledge of how Paperclip stores files on S3 has escaped me (the app was written almost 3 years ago).
  • Viewing the bucket's content within the S3 console lists what appears to be meta-data text-files containing a link to the image.
  • I can't seem to find any image files within the bucket itself (via the S3 web console).

Solutions?

  • I've tried various applications like Cyberduck and Buckets but they all time out trying to request the bucket's content.
  • It seems odd that my production bucket only contains meta-data text files describing an image's location; why can't I see the images in the console itself?
  • Is there some easy script I can run to grab all images?

Can you provide some additional information about your has_attached_file method declared in your model?

You could do something like this assuming you have has_attached_file :photo :

Model.find_each do |record|
  puts record.photo.url
end

puts will obviously just show you the URL. You'll want to script iterating over the list and fetching them with curl or wget.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM