如何为amazon s3图像添加Expires标头?

Moh*_*ain 6 optimization performance ruby-on-rails amazon-s3 paperclip

在我的模型中,它使用的是回形针.我添加了行代码,但仍然无法正常工作

 has_attached_file :attachment, {
    :styles => {
      :medium => ["654x5000000>", :jpg],
      :small => ["260x50000000>", :jpg], 
      :thumb => ["75x75#", :jpg],
      :facebook_meta_tag =>["200x200#", :jpg] 
    },
    :convert_options => {
       :medium => "-quality 80 -interlace Plane",
       :small => "-quality 80 -interlace Plane",
       :thumb => "-quality 80 -interlace Plane",
       :facebook_meta_tag => "-quality 80 -interlace Plane" 
       },
       :s3_headers => { 'Cache-Control' => 'max-age=315576000', 'Expires' => 10.years.from_now.httpdate } 
    }.merge(PAPERCLIP_STORAGE_OPTIONS)
Run Code Online (Sandbox Code Playgroud)

PS:我在GTmetrix.com上进行了测试,根据他们的统计数据,亚马逊图片中没有到期标题.

mwa*_*her 5

为了扩展James对其他人不确定如何重新处理旧附件的回答,有两种方法可以做到:

1)通过rake重新处理所有附件(可选择每个CLASS)

rake paperclip:refresh CLASS=User
Run Code Online (Sandbox Code Playgroud)

2)重新处理特定附件(例如通过迁移)

User.where("attachment IS NOT NULL").find_each do |user|
  user.attachment.reprocess!
end
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation#generatingregenerating-your-thumbnails