简体   繁体   中英

Copy images from one S3 bucket to another with specified path prefixes

I have an S3 bucket setup already, it contains images of a photo gallery, uploaded from my Rails app using PaperClip. Images are accessible via some arbitrary URLs like: http://s3.amazonaws.com/oldbucket/images/files/000/001/920/original/40a6885fc09c8ed4e1e3745d7f7fb770.jpg?1415766995 .

Kindly advice me the best option considering following requirements:

  1. I have to copy those images to another S3 bucket in another AWS account
  2. I want to make the new image URLs according to specific patterns, like: .../newbucket/{userid}/{galleryid}/{image-size}.jpg
  3. I want to create multiple versions of each image, according to size (original, thumbnail and icon)

Any options using Rails gem or software that would do above would be helpful.

Thanks

For this you need to add carrierwave gem for saving image from remote url. You can also do with paperclip.

First create a seed file without adding carrierwave uploader to your app. I am considering User as model and avatar as image.

User.all.each{|u| puts user.avatar.url}`

Now remove paperclip and add carrierwave This will give you list of all images. Now add it to seed file for model you want to add this images.

class Modelx
  mount_uploader :avatar, AvatarUploader
end

So your seed file should have entries like.

Modelx.create([{:avatar_remote_url => image_url1}, {:avatar_remote_url => image_url2},.....])

You can set specific path and also create multiple dimension images using carrierwave.

REfrence url for carrierwave here .

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