这里我们有简单的rails模型:
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
成功保存后,我检查了在亚马逊上创建的内容,我只有 :original 样式。问题是应该有 :large、:medium、:path、:for_index 等样式。
我试着做
a.attachment.reprocess!
但它忘记了所有样式,只有 :original。
如何在 S3 上更新文件时创建所有样式?