Can I configure Paperclip to create HTTPS URLs?

I use Paperclip to manage user uploaded images on a site that is fully supported by HTTPS. To avoid the dumb security warnings on IE7 / IE8, I also need to serve these images via SSL. I usually draw my images using the following:

<%= image_tag @product.image.url(:large) %> 

Where

 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" 

and generated image url:

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

Is there a magic β€œClip” option to change it to:

 https://s3.amazonaws.com/media.example.com/images/6/large/image123.JPG 
+56
ruby-on-rails ruby-on-rails-3 amazon-s3 paperclip
Oct 26 '11 at 1:17
source share
2 answers

You just need to add:

 :s3_protocol => :https 

This is described in the documentation .

There are several S3 specific options for has_attached_file:
...

  • s3_protocol : protocol for the URLs generated for your S3 assets. It can be either "http" or "https". The default is "http" when your: s3_permissions: public_read (default) and "https when your: s3_permissions is something else.
+99
Oct. 26 2018-11-11T00:
source

To update your code, simply add: s3_protocol, as shown below:

 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" 
+24
Jul 31 '13 at 21:32
source



All Articles