我正在使用Paperclip管理完全在HTTPS下提供服务的网站上的用户上传图片。为了避免IE7 / IE8上的愚蠢安全警告,我还需要通过SSL提供这些图像。我通常使用以下内容渲染我的图像:
<%= image_tag @product.image.url(:large) %>
,其中
class Product < ActiveRecord::Base
has_attached_file :image,
:styles => {
:large => {:geometry => "616x450#"}
},
:storage => :s3,
:s3_credentials => {:access_key_id => "xxx", :secret_access_key => "xxx"},
:path => ":attachment/:id/:style/:basename.:extension",
:bucket => CONFIG['s3_media_bucket'],
:default_url => "/assets/image_missing.png"
生成的图片网址如下:
http://s3.amazonaws.com/media.example.com/images/6/large/image123.JPG
是否有魔术回形针选项可将其更改为:
https://s3.amazonaws.com/media.example.com/images/6/large/image123.JPG
答案 0 :(得分:97)
您只需添加:
:s3_protocol => :https
has_attached_file有一些特定于S3的选项:
...
s3_protocol
:为S3资产生成的网址的协议。可以是'http'或'https'。当你的:s3_permissions是:public_read(默认值)时默认为'http',当你的:s3_permissions是其他任何内容时,默认为'https'。
答案 1 :(得分:23)
要更新代码,请按以下步骤添加:s3_protocol:
class Product < ActiveRecord::Base
has_attached_file :image,
:styles => {
:large => {:geometry => "616x450#"}
},
:storage => :s3,
:s3_credentials => {:access_key_id => "xxx", :secret_access_key => "xxx"},
:s3_protocol => :https,
:path => ":attachment/:id/:style/:basename.:extension",
:bucket => CONFIG['s3_media_bucket'],
:default_url => "/assets/image_missing.png"