嗨我會對一個簡單的耙任務來完成這一點。它看起來像這樣的事情(未測試):
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)
而這不言而喻 - 請確保您在臨時環境中測試這個!
祝你好運。