2014-03-19 46 views
1

我正在将新回形针附件上传到AWS S3。但是我需要将文件系统上的很多旧映像迁移到S3。我正在尝试这个耙子任务,但我无法弄清楚我应该如何在S3上提供铲斗路径。将旧回形针图像从文件系统迁移到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 
+0

你看的AWS s3宝石:http://amazon.rubyforge.org? –

+0

@ArvindMehra嗨,你能告诉我你为什么搬到S3,使用文件系统不是一个好主意吗? – medBo

回答

0

解决它......我改变了我的rake任务到这一点,我又救了我的每一个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 
相关问题