[英]migrating old paperclip images from filesystem to S3
I am uploading new paperclip attachments to AWS S3. 我正在将新的回形针附件上传到AWS S3。 But i have a lot of old images on the file system that needs be migrated to S3.
但是我在文件系统上有很多旧映像,需要迁移到S3。 I am trying this rake task but i am not able to figure out how i should provide the path to bucket on S3.
我正在尝试执行此rake任务,但是我无法弄清楚如何在S3上提供存储桶的路径。
task :copy_paperclip_data => :environment do
@toycars = ToyCar.find :all
@toycars.each do |toycar|
unless toycar.image_file_name.blank?
filename = Rails.root.join('public', 'system', 'images', toycar.id.to_s, 'original', toycar.image_file_name) # this allows me to change path on filesystem, but i want to make it upload on s3
if File.exists? filename
image = File.new filename
toycar.image = image
toycar.save
image.close
end
end
end
end
Solved it... I changed my rake task into this, I am saving my every ToyCar object image again and it does the job.... 解决了...我将耙任务更改为此,我再次保存了我的每个ToyCar对象图像,并且可以完成工作。...
namespace :migrate_to_s3 do
desc "Upload images to S3"
task :toy_cars => :environment do
toy_cars = ToyCar.all
toy_cars.each do |car|
image = Dir["#{Rails.root}/public/system/#{car.logo.path}"].first
if image.present?
car.update(:logo => File.open(image))
puts "uploading"
end
end
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.