简体   繁体   English

图片成功上传到AWS s3存储桶,但未显示在我的网站上

[英]Images upload successfully to aws s3 bucket but do not display on my site

I am using Rails with Heroku and AWS S3 to deploy a pinterest like website that I created through a tutorial. 我将Rails与Heroku和AWS S3一起使用,以部署通过教程创建的pinterest这样的网站。 Users are successfully able to upload images to my s3 bucket. 用户可以成功将图像上传到我的s3存储桶。 The problem is, uploaded images are supposed to display in the index (and show) but do not. 问题是,上载的图像应该显示在索引中(并显示),但不显示。

I created a bucket policy so the 'getobject' method is enabled. 我创建了一个存储桶策略,因此启用了“ getobject”方法。

{
"Id": "Policy1445210052484",
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "Stmt1445209989872",
        "Action": [
            "s3:GetObject"
        ],
        "Effect": "Allow",
        "Resource": "arn:aws:s3:::wyattsbucket/*",
        "Principal": "*"
    }
]

} }

Here is a screenshot of the postings on my site: 这是我网站上发布的屏幕截图:

在此处输入图片说明 Heroku is not receiving any errors so I believe the problem is either in the S3 bucket or in my Rails environment. Heroku没有收到任何错误,因此我相信问题可能出在S3存储桶中还是我的Rails环境中。 This is my first post, please forgive the amateur formatting, and if you have any ideas please let me know! 这是我的第一篇文章,请原谅业余格式化,如果您有任何想法请告诉我!

Thanks in advance. 提前致谢。

= form_tag pins_path = form_tag pins_path

views/pins/index.html.haml views / pins / index.html.haml

#pins.transitions-enabled
  - @pins.each do |pin|
    .box.panel.panel-default
      = link_to (image_tag pin.image.url), pin
      .panel-body
        %h2= link_to pin.title, pin
        %p.user
        Submitted by
        = pin.user.email

models/pin.rb 型号/pin.rb

class Pin < ActiveRecord::Base
    acts_as_votable
    belongs_to :user
    has_attached_file :image, styles: { medium: "500x500>" }
    validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/


end

I'm guessing your issue is with your policy. 我猜您的问题出在您的保单上。 If you put the URL in your browser, can you view the image? 如果将URL放在浏览器中,可以查看图像吗?

You could also try the below policy. 您也可以尝试以下政策。 I'm not that familiar with S3 policy's but this works for get's for me. 我对S3策略不太熟悉,但这对我来说很有效。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::wyattsbucket/*"
        }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM