【问题标题】:How to Add Expires headers for amazon s3 images?如何为亚马逊 s3 图像添加过期标题?
【发布时间】:2012-10-11 05:32:53
【问题描述】:

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

 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)

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

【问题讨论】:

  • 更改后是否重新上传了之前的所有附件?
  • @James 我需要吗?我没有意识到这一点。如果我必须重新处理所有图像,请告诉我..
  • 每当您更改回形针设置时,如果您希望它们与更新后的设置匹配,则需要重新处理所有以前的附件。

标签: ruby-on-rails performance optimization amazon-s3 paperclip


【解决方案1】:

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

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

rake paperclip:refresh CLASS=User

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

User.where("attachment IS NOT NULL").find_each do |user|
  user.attachment.reprocess!
end

欲了解更多信息,请参阅https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation#generatingregenerating-your-thumbnails

【讨论】:

    【解决方案2】:

    您似乎没有重新处理/上传旧附件,这就是它们的标题没有更改的原因。

    【讨论】:

      【解决方案3】:

      如果有人需要使用动态过期标头获取附件的 URL,这对我有用:来自回形针文档 link 的 attachment.expiring_url(60 * 60)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-07
        • 2017-08-01
        • 1970-01-01
        • 2014-05-08
        • 1970-01-01
        • 1970-01-01
        • 2016-01-13
        • 2012-10-11
        相关资源
        最近更新 更多