图片已上传到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仪表板的网址中该地区显示region=us-west-2
,但在Google上搜索并阅读其他论坛和帖子后,使我相信,如果我在美国,我所在的地区应该设置为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/回形针有关的代码:
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"
我正在这样的视图中显示:
and I am displaying in the view like this:
<%= 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'
- Create a new initializer file i.e. config/initializers/paperclip.rb
- Add following in this file
Paperclip::Attachment.default_options[:url] = ':s3_domain_url' Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-2.amazonaws.com'
要获取有关您所在地区的详细信息,请访问
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屋!