How does one use s3_host_alias and s3_alias_url to get the Cloudfront URL?

1,939 views
Skip to first unread message

Matt M

unread,
May 5, 2009, 6:26:36 PM5/5/09
to Paperclip Plugin
I've been trying to use the s3_host_alias option to specify my
cloudfront URL, but the #url method keeps returning the
s3.amazonaws.com url.

Here's my Picture model with the attachment:

class Picture < ActiveRecord::Base

has_attached_file :image, :path =>
"images/:class/:id/:basename.:style.:extension",
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/
s3.yml",
:bucket => 'themesagogo',
:s3_host_alias =>
'themesagogo1.thrivesmart.net'

validates_attachment_size :image, :less_than => 1.megabytes

end


And here's how I'm calling URL:

@picture.image.url


Is there something I'm missing in the options sent to
has_attached_file, or am I calling the wrong method (something other
than .url)?

I hope this has an easy answer - I just couldn't find any documented
examples of it anywhere.

Thanks!


Matt M

unread,
May 7, 2009, 4:00:38 PM5/7/09
to Paperclip Plugin
Solution found, looked at test examples. I needed to include :url =>
':s3_alias_url'

Victor Stan

unread,
Nov 5, 2011, 2:27:23 PM11/5/11
to papercli...@googlegroups.com
Thanks this is what I was looking for . For example completeness I will include my setup:

  has_attached_file :background_image,
       :styles => {
       :thumb    => ["100x100#", :jpg],
       :original => ["1680x1050>", :jpg] },
     :storage => :s3,
     :s3_credentials => "#{Rails.root}/config/s3.yml",
     :url => ':s3_alias_url',
     :s3_host_alias => "example.cloudfront.net",
     :path => "/:class/:id/:style/:clean_filename",
     :default_style => :original,
     :default_url => '/assets/rails.png',
     :convert_options => { :thumb => "-quality 60", :original =>  "-quality 70", :all => '-strip -trim'}
Reply all
Reply to author
Forward
0 new messages