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년 전5247회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠