加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用Paperclip和AWS S3的自定义URL

发布时间:2020-12-17 03:24:29 所属栏目:百科 来源:网络整理
导读:我们使用带有aws-sdk gem的Paperclip在我们的Rails应用程序中存储和显示图像: class User ActiveRecord::Base has_attached_file :image,storage: :s3,s3_credentials: 'config/s3.yml',s3_protocol: :https,styles: { curriculum: '120x120',medium: '600x
我们使用带有aws-sdk gem的Paperclip在我们的Rails应用程序中存储和显示图像:

class User < ActiveRecord::Base
  has_attached_file :image,storage: :s3,s3_credentials: 'config/s3.yml',s3_protocol: :https,styles: {
                        curriculum: '120x120>',medium: '600x600>',thumb: '200x200>'
                    },default_url: 'missing_photo.png'
end

如果我然后使用<%= image_tag current_user.image.url%>在html.erb文件中,我得到以下HTML:< img src =“https://s3.amazonaws.com/u0026lt;my_bucketu0026gt;/users/images/000/000/001/medium/my_image.png? 1419989041" 取代. 我如何获得https://s3.amazonaws.com/u0026lt;my_bucketu0026gt;成为https://example.com等自定义网址?我在Cloudfront中设置了所有域以及SSL证书. 我在Paperclip S3 Storage documentation中查了一下.有一个:url选项,但我为该选项编写的内容似乎无效.

解决方法

我刚遇到这个问题,这里是我必须使用的设置

:s3_host_alias => "s3.example.com",:url => ":s3_alias_url",:path => ":class/:attachment/:id.:style.:extension"

从this link开始,我了解到,除了:s3_host_alias和:url之外,你必须指定路径,这样你就不会得到

Paperclip::InfiniteInterpolationError

Kinda运作良好,因为默认的回形针路径无论如何都有点不可思议.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读