2015-10-18 93 views
0

我正在使用Rails和Heroku以及AWS S3来部署通过教程创建的pinterest网站。用户可以成功地将图像上传到我的s3存储桶。问题是,上传的图像应该显示在索引(和显示)中,但不要。图片已成功上传到aws s3存储桶但未在我的网站上显示

我创建了一个存储桶策略,以便启用'getobject'方法。

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

}

这里是我的网站上张贴的截图:

enter image description here 的Heroku没有收到任何错误,所以我认为这个问题是无论是在S3桶或在我的Rails环境。这是我的第一篇文章,请原谅业余的格式,如果您有任何想法,请让我知道!

在此先感谢。

=的form_tag pins_path

的意见/销/ 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 

型号/ 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 
+0

请为HTML打开一个新问题! – user2954587

回答

1

我猜你的问题是与你的政策。如果您将URL放入浏览器中,您是否可以查看图像?

你也可以尝试下面的政策。我不太熟悉S3政策,但这对我来说很有用。

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

@wytwtwade你,我也可以看到它。该政策正在工作。它必须是你的HTML中的东西。你能发布你的HTML吗?看看这个jsfiddle工作img标签。 http://jsfiddle.net/cu033fm8/ – user2954587

+0

我更新了我的S3政策以符合你的要求,但仍然没有运气。我不确定您是指图片网址还是英雄网址,但是如果您指的是图片网址,则可以使用!来自存储分区的图片网址显示图片。 https://s3-us-west-1.amazonaws.com/wyattsbucket/pins/images/000/000/016/medium/as_surf_slater_2048.jpg – wyattwade

+0

是的,我会发布我的html.haml和我的模型。再次感谢你的帮助。 – wyattwade

相关问题