gpt4 book ai didi

ruby-on-rails - 是否可以配置 Paperclip 为 S3 生成 HTTPS url?

转载 作者:行者123 更新时间:2023-12-03 05:45:23 25 4
gpt4 key购买 nike

我正在使用 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"

生成的图像 URL 类似于:

http://s3.amazonaws.com/media.example.com/images/6/large/image123.JPG

是否有一个神奇的回形针选项可以将其更改为:

https://s3.amazonaws.com/media.example.com/images/6/large/image123.JPG

最佳答案

您只需添加:

:s3_protocol => :https

这已涵盖in the documentation .

There are a few S3-specific options for has_attached_file:
...

  • 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.

关于ruby-on-rails - 是否可以配置 Paperclip 为 S3 生成 HTTPS url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7897710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com