2014-10-28 63 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 
相關問題