2
下面我們就簡單的軌道模型
class Attachment < ActiveRecord::Base
has_attached_file :attachment, styles: lambda { |attachment|
store_sizes?(attachment) ? {
:large => ["414x300>",:png],
:medium => ["138x100>", :png],
:for_index => ["180x100", :png],
:for_preview => ["180x100", :png],
:thumb => ["62x42>", :png],
:approval => ['285x122#', :png],
:origin_png => ['100%', :png]
} : {} },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:s3_headers => {"Content-Disposition" => "attachment"}
[...等等...]
由於任務的複雜性我得到了,我有大量的數據庫附件,但它們不存在於S3存儲上。
所以問題是:
a = Attachment.last
a.attachment
這將返回看中的網址,如:http://s3.amazonaws.com/attachments/000/232/055/original/blah.JPG?1370449427
所以現在我希望把我的文件附件屬性:
my_new_file = File.open('/tmp/somefile.jpg')
a.attachment = my_new_file
a.attachment.save
後成功保存我檢查在亞馬遜上創建了什麼,而我只有:原創風格。 問題是應該有:large,:medium,:path,:for_index等樣式。
我試着做
a.attachment.reprocess!
但它忘記所有的風格,只有有:原。
如何在S3上更新文件時創建所有樣式?