I have a model with a avatar
paperclip attach. It has now a plain standard path
has_attached_file :avatar,
:path => \"/:id-:style-:filename\"
<
This rake task should do the trick. I tried it with aws-sdk 1.5.2 and ruby 1.9.3p194.
The new_key
should map to your new paperclip path. Don't forget to set :acl
according to your needs.
namespace :data do
desc 'aws images migration'
task :migrate_images do |t, args|
s3 = AWS::S3.new(:access_key_id => 'XXX', :secret_access_key => 'XXX')
bucket = s3.buckets['your-bucket-name']
bucket.objects.each do |object|
new_key = object.key.gsub(........)
new_object = bucket.objects[new_key]
object.copy_to new_object, {:acl => :public_read}
end
end
end
The original file should be deleted manually or using a similar task, once you are sure the new file is correct.