Is it possible to configure Paperclip to produce HTTPS urls?

有些话、适合烂在心里 提交于 2019-11-28 21:00:31
Jordan Running

You simply need to add:

:s3_protocol => :https

This is covered 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.

To update your code just say, add the :s3_protocol as following:

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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!