[英]How do I reference images in my S3 bucket from local dev app?
Please see: On Amazon S3 I'm able to give an individual object download rights but cannot for the entire bucket for the next evolution of this question. 请参阅: 在Amazon S3上,我可以赋予单个对象下载权,但不能为整个存储桶提供该问题的下一个发展。
I've got a bucket with all my images uploaded. 我的所有图片都已上传到存储桶中。 I'm trying to access them via their url as instructed by https://devcenter.heroku.com/articles/s3 . 我正在尝试按照https://devcenter.heroku.com/articles/s3的指示通过其URL访问它们。 I of course want to make sure I can access them before I upload my latest changes to my live app. 我当然想确保在将最新更改上传到实时应用程序之前可以访问它们。 I've got the yml set up appropriately as far as I can tell, but the images are not loading when I visit the site running locally on WEBRICK. 据我所知,我已经适当地设置了yml,但是当我访问在WEBRICK上本地运行的站点时,图像未加载。 I have not made any changes to the AWS files in my rubygems directory. 我尚未对rubygems目录中的AWS文件进行任何更改。 Here's an example of the reference I'm using to display the image: 这是我用来显示图像的参考示例:
<%= image_tag("https://s3-us-west-2.amazonaws.com/mybucket/someimage.jpg") %>
Can anyone provide me with some instructions? 谁能给我一些指示? I know there are instructions for adding code to the included AWS files, but I cannot understand them enough to go in there and monkey around. 我知道有将代码添加到所包含的AWS文件中的说明,但是我对它们的理解不够深,无法深入其中。 Thanks. 谢谢。
I added the following to my bucket policy: 我在存储桶策略中添加了以下内容:
{
"Id": "somepolicy",
"Statement": [
{
"Sid": "someid",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::myapp/mykey",
"Principal": {
"AWS": [
"*"
]
}
}
]
}
I am still unable to access the images. 我仍然无法访问图像。 Is GetObject
the appropriate action to allow? GetObject
是允许的适当操作吗?
You should be using the paperclip gem for image uploading. 您应该使用回形针gem进行图像上传。 I know it doesn't seem necessary, but when it comes to allowing users to upload to disk, it's better to leave it to the professionals. 我知道这似乎没有必要,但是在允许用户上传到磁盘时,最好将它留给专业人员。 (Why re-invent the wheel?). (为什么要重新发明轮子?)。
With paperclip, you can do things like 使用回形针,您可以执行以下操作
User.profile_pic.url
or 要么
User.images.first.image.url
I certainly think it's the way to go. 我当然认为这是要走的路。
Paperclip is great solution for uploading and serving files but it sounds like you have already uploaded all of the content you intend to serve. 回形针是上传和提供文件的绝佳解决方案,但听起来您已经上传了要提供的所有内容。 This is a permissions issue with your S3 bucket. 这是S3存储桶的权限问题。
Amazon Sample bucket policies: Amazon Sample存储桶策略:
http://docs.aws.amazon.com/AmazonS3/latest/dev/AccessPolicyLanguage_UseCases_s3_a.html http://docs.aws.amazon.com/AmazonS3/latest/dev/AccessPolicyLanguage_UseCases_s3_a.html
Big thanks to everyone that worked with me on this problem, especially @LarryMcKenzie. 非常感谢在这个问题上与我合作的所有人,尤其是@LarryMcKenzie。 The problem is that you need to set file permissions on upload and there is no way to mass assign permissions to all objects in a bucket. 问题在于,您需要在上传时设置文件权限,并且无法批量分配存储桶中所有对象的权限。
Solution: I reuploaded all of the images with the Open/Download flag set to true for everyone. 解决方案:我将所有人的“打开/下载”标志设置为true,重新上传了所有图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.