Rails paperclip amazon aws s3 gem how to change image url?

In my model, I have:

  has_attached_file :image,
          :storage => :s3,
          :styles => { :original => ["300x250>", :png], :small => ["165x138>", :png], :mini => ["120x120>", :png] },
          :path => 'images/vind/:style/:id/:basename.:extension',
          :url => 'images/vind/:style/:id/:basename.png',
          :bucket => 'konkurrencerher',
          :s3_credentials => {
          :access_key_id => 'x',
          :secret_access_key => 'x'
  }

      

The only problem is that amazon s3 hostname has been added to the url in question.

I have a solution to this, but a little ugly:

<%= image_tag(kon.photo.image.url(:small).gsub("http://s3.amazonaws.com/konkurrencerher", ""), :class => 'koni') %>

      

But how can the URL of an image be determined in a model without an Amazon S3 hostname?

+3


source to share


2 answers


My solution created a file in the init map like this:

Paperclip.interpolates(:s3_path_url) { |attachment, style|
  "#{(attachment.path).gsub("images/", "")}"
}

      

And then the url should be:



:url => ':s3_path_url'

      

This is a much better solution.

0


source


Take a look at Paperclip::Storage::S3

, especially at :s3_host_alias

.

You can try customizing has_attached_file

with the following additional parameters



 :url => ':s3_alias_url',
 :s3_host_alias => "example.domain.net"

      

Hope it helps.

+2


source







All Articles