Diplay pictures stored in s3 to web page

0

I am builiding a web app with flask that allows user to update pictures to it. The pictures then get displayed on the web page.
I was able to connect flask with S3 to upload pictures to my bucket, but I can not display them on my page.

Is it possible to use something like this in my html to return the pictures?
<img src="https://oldports-static-images.s3.us-east-2.amazonaws.com/fun_E4173.jpg " width="200px" height="200px">
why wouldn't this work?

My bucket has public read permissions (I think), I would expect that if I opened the link I would see the pictures? I get an error message.
https://oldports-static-images.s3.us-east-2.amazonaws.com/fun_E4173.jpg

I appreciate any help I can be given, I am new to development and this part is overwhelming to me.

已提问 5 年前5246 查看次数
2 回答
0
已接受的回答

Hi,
Most likely you just need to set the Bucket Policy to public so that anyone can view the images (and they will be available for use to embed in your web page).

  1. Go to Services - Amazon S3
  2. Click on the link to your bucket "oldports-static-images"
  3. Click on Permissions. Make sure you have "Block public access" set to Off. If no, hit the Edit Button and set to Off.
  4. If "Bucket Policy" is NOT marked "Public", then click on Bucket Policy (on Permissions tab).
  5. Enter the Following Bucket Policy:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::oldports-static-images/*"
        }
    ]
}
  1. Hit Save
  2. You should now see the Bucket Policy and Permissions both tagged with "Public"
    You should now be able to upload any files to this bucket and reference them with your URL.

Hope this helps!
-randy

已回答 5 年前
0

Thank you very much! It worked!

已回答 5 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则