图片上传到 aws,但无法在视图中查看 [英] images uploaded to aws, but can't be viewed in the view
问题描述
我刚刚将 AWS 与我的 rails/heroku 应用程序集成,并且我正在使用回形针.我可以上传文件(照片)并在 AWS 中查看它们,但是它们没有显示在视图中.我没有收到任何错误,也没有在其他帖子中找到有效的解决方案.
I have just integrated AWS with my rails/heroku app and I am using paperclip. I am able to upload files (photo's) and see them in AWS, however they are not showing up in the view. I am not getting any errors, and have not found a working solution in other posts.
我似乎可以在浏览器中查看图像,并且权限设置为公开:
It seems I am able to view the image in a browser, and that permissions are set to public:
我怀疑我的地区可能有误,在我的 aws 仪表板的 url 中,该地区说 region=us-west-2
但谷歌搜索和阅读其他论坛和 SO 上的帖子引导我相信如果我在美国,我的地区应该设置为 us-east-1
- 目前我已将其设置为后者.不知道是不是这个问题.
I suspect that I may have my region wrong, in the url of my aws dashboard the region says region=us-west-2
yet googling and reading through other forums and posts on SO leads me to believe that if I am in the US my region should be set to us-east-1
- currently I have it set to the latter. Not sure if this is the problem.
这是 AWS 上图片的链接:https://s3.amazonaws.com/giving-tree-images/avatars/1/medium/02108_navajoland_1440x900.jpg
Here is a link to the image on AWS:https://s3.amazonaws.com/giving-tree-images/avatars/1/medium/02108_navajoland_1440x900.jpg
这是我的模型中与 aws/paperclip 有关的代码:
here is the code pertaining to aws/paperclip in my model:
:storage => :s3,
# :s3_host_name => "s3-us-east-1.amazonaws.com",
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
},
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:default_url => "default_img.png"
我在视图中显示如下:
<%= image_tag @user.avatar.url(:medium) %>
如果有人能指出我正确的方向,我会很高兴...需要任何其他信息,请告诉我!
I would love it if someone could point me in the right direction... Any additional info needed, please let me know!
推荐答案
我也遇到了同样的问题,所以我是这样解决的:
I also faced the same issue, so this is how I solved it:
- 创建一个新的初始化文件,即 config/initializers/paperclip.rb
- 在此文件中添加以下内容
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-2.amazonaws.com'
要获取有关您所在地区的详细信息,请访问 aws
To get details about your region, go to aws
注意:将 s3-us-west-2.amazonaws.com
替换为您自己的主机名
Note : Replace s3-us-west-2.amazonaws.com
with your own host name
参考:https://devcenter.heroku.com/articles/paperclip-s3一个>
这篇关于图片上传到 aws,但无法在视图中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!