[英]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 problem is just that there is added the amazon s3 hostname to the url in view. 问题只是在视图中添加了amazon s3主机名到url。
I have a solution to this, but is a bit ugly: 我有一个解决方案,但有点难看:
<%= image_tag(kon.photo.image.url(:small).gsub("http://s3.amazonaws.com/konkurrencerher", ""), :class => 'koni') %>
But, how is it possible to define the image url in the model, without the Amazon S3 hostname? 但是,如何在没有Amazon S3主机名的情况下在模型中定义图像URL?
Take a look at Paperclip::Storage::S3
, especially on the :s3_host_alias
. 看一下
Paperclip::Storage::S3
,尤其是:s3_host_alias
。
You can try configuring your has_attached_file
with the following additional options 您可以尝试使用以下附加选项配置
has_attached_file
:url => ':s3_alias_url',
:s3_host_alias => "example.domain.net"
Hope this helps. 希望这可以帮助。
My solution created a file in the initializers map with 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. 这是一个更好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.