是否可以配置Paperclip为S3生成HTTPS URL? [英] Is it possible to configure Paperclip to produce HTTPS urls for S3?

查看:110
本文介绍了是否可以配置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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆