是否可以配置 Paperclip 为 S3 生成 HTTPS url? [英] Is it possible to configure Paperclip to produce HTTPS urls for S3?
本文介绍了是否可以配置 Paperclip 为 S3 生成 HTTPS url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Paperclip 来管理完全在 HTTPS 下提供服务的网站上用户上传的图像.为了避免 IE7/IE8 上愚蠢的安全警告,我还需要通过 SSL 提供这些图像.我通常使用以下内容渲染我的图像:
I'm using Paperclip to manage user-uploaded images on a site that is served entirely under HTTPS. In order to avoid the silly security warnings on IE7/IE8, I need to also serve these images over SSL. I typically render my images using something like the following:
<%= 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"
生成的图像 URL 类似于:
and the image URL produced is something like:
http://s3.amazonaws.com/media.example.com/images/6/large/image123.JPG
是否有一个神奇的回形针选项可以将其更改为:
Is there a magic Paperclip option to change this to:
https://s3.amazonaws.com/media.example.com/images/6/large/image123.JPG
推荐答案
您只需添加:
:s3_protocol => :https
这在文档中有介绍.
has_attached_file 有一些 S3 特定的选项:
...
There are a few S3-specific options for has_attached_file:
...
s3_protocol
:生成到您的 S3 资产的 URL 的协议.可以是http"或https".当您的 :s3_permissions 为 :public_read(默认值)时默认为http",当您的 :s3_permissions 为其他任何内容时默认为https".
s3_protocol
: The protocol for the URLs generated to your S3 assets. Can be either ‘http’ or ‘https’. Defaults to ‘http’ when your :s3_permissions are :public_read (the default), and ‘https’ when your :s3_permissions are anything else.
这篇关于是否可以配置 Paperclip 为 S3 生成 HTTPS url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文