[英]How to Add Expires headers for amazon s3 images?
在我的模型中,它使用的是回形針。 我添加了這行代碼,但仍然無法正常工作
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對其他人不確定如何重新處理舊附件的回答,有兩種方法可以做到:
1)通過rake重新處理所有附件(可選擇每個CLASS)
rake paperclip:refresh CLASS=User
2)重新處理特定附件(例如通過遷移)
User.where("attachment IS NOT NULL").find_each do |user|
user.attachment.reprocess!
end
看起來您沒有重新處理/上傳舊附件,這就是為什么他們的標題沒有改變的原因。
如果有人需要使用動態過期標題獲取附件的URL,這對我有用:來自paperclip文檔鏈接的 attachment.expiring_url(60 * 60)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.