我创建了一个运行在Heroku上的Rails应用程序,有纸夹和S3。我已经设法通过网站将图像上传到我的S3桶中(我可以看到它们显示在Amazon控制面板上的桶中)。
但是当我添加一个Image标签,即<%= image_tag x.photo.url %>
时,我得到了下面的html(这里省略了标签),没有显示任何图像!
img alt="Test_tree" src="http://s3.amazonaws.com/hiphotos/ads/photos/000/000/015/original/test_tree.jpg?1344661020"
为什么我看不到图像,即使它们在桶中?
2条答案
按热度按时间jhdbpxl91#
创建一个名为回形针初始化器的文件:
或者你也可以把它放在
production.rb
里面:gmol16392#
首先,您尝试在代码中使用的URL是:
当您在浏览器中访问该链接时,将看到以下内容:
因此,如果我们使用正确的端点修改url,我们会得到:
它返回正确的图像。
如果您使用的是欧洲桶,这种情况可能会发生,这可能是您正在使用的宝石将事情推到s3的错误。
有大量的文章介绍如何让回形针,S3和欧洲桶一起玩得很好。
不过我发现,自从我开始使用asset_sync gem(它使用Fog而不是aws-s3 gem)以来,我在使用回形针和S3方面没有遇到任何麻烦。
所以我怀疑Fog在解决这个问题上有一定的作用。如果你在使用其他的东西,我建议你换用Fog。