2014-10-28 65 views
0

我使用Rails(4.0.1)和Paperclip(4.2.0)将一些图像保存到S3。如何将由Paperclip保存的旧图像迁移到新样式并将其保存为s3(并且不在本地保存新文件)? (Rails)

我曾经有一个模型PropertyImage:

class PropertyImage < ActiveRecord::Base 
    has_attached_file :picture, 
    storage: :s3, 
    s3_credentials: CONFIG['s3'], 
    s3_protocol: (Rails.env.development? ? "http": "https") 
end 

现在我要迁移的旧图像给新的大小,所以我更新了模型:

class PropertyImage < ActiveRecord::Base 
    has_attached_file :picture, 
    storage: :s3, 
    s3_credentials: CONFIG['s3'], 
    s3_protocol: (Rails.env.development? ? "http": "https"), 
    styles: { 
     thumb: '100x100>', 
     large: '633x460>', 
     medium: '301x240>'  
    } 
end 

现在,当我尝试使用与回形针rake paperclip:refresh提供的耙:

RAILS_ENV=development bundle exec rake paperclip:refresh CLASS=PropertyImage 

而当我检查日志,我越来越:

(0.2ms) BEGIN 
    Property Load (0.7ms) SELECT "properties".* FROM "properties" WHERE ((hidden IS FALSE OR hidden IS NULL) AND sale_or_rental = 'S') AND "properties"."id" = $1 ORDER BY "properties"."id" ASC LIMIT 1 [["id", 20]] 
    SQL (0.6ms) UPDATE "properties" SET "updated_at" = '2014-10-28 12:33:58.382649' WHERE "properties"."id" = 20 
    (1.7ms) COMMIT 
[paperclip] copying /property_images/pictures/000/000/074/original/e9ad004a-09f1-4af3-85c3-772fe3e99acd.gif to local file /var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/T/2c5a0dd4db750ff6c32b123df2d933ce20141028-28547-j997pz.gif 
[AWS S3 200 0.209569 0 retries] get_object(:bucket_name=>"babylon_development",:key=>"property_images/pictures/000/000/074/original/e9ad004a-09f1-4af3-85c3-772fe3e99acd.gif") 

两件事情,我注意到这里:

1耙正试图在本地保存原始图像/var/folders/*(而不是S3)

2-耙也没有创造不同大小(拇指,大,中)

任何帮助将不胜感激。

回答

1

我不得不添加missing_styles就像:

bundle exec rake paperclip:refresh:missing_styles class=PropertyImage 
相关问题