嗨我会对一个简单的耙任务来完成这一点。它看起来像这样的事情(未测试):
desc "port files to s3"
task :port => :environment do
AWS::S3::Base.establish_connection!(
:access_key_id => S3_CONFIG['access_key_id'],
:secret_access_key => S3_CONFIG['secret_access_key']
)
Images.all.each do |image|
new_image_path = "/images/#{image.id}/#{image.file_name_with_extension}"
AWS::S3::Object.store(new_image_path,open(image.current_path_to_image),S3_CONFIG['bucket_name'],:access => :public_read)
end
end
的几个注意事项: 如果您正在使用回形针管理和访问,你会想它们存储在S3这样回形针可以访问其中的文件。要做到这一点,使用Paperclip::Interpolations.interpolate
方法。如:
new_image_path = Paperclip::Interpolations.interpolate("/accounts/:account_id/images/:id/:style/:basename.:extension",image,:small)
而这不言而喻 - 请确保您在临时环境中测试这个!
祝你好运。