Skip to content

S3 AWS doesn't show my image, but I am able to download it

0

In my bucket, I am able to download the images that I put inside. However, if I click on the link to display them, it doesnt work, and it returns the error:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>P941GTWVX65ACX5J</RequestId>
<HostId>slS5tLKmSxGBeyrh+KJ0C4rkRki/R1ER6wpu8rJZ3xtNOpAVm2uhyEygikajRCXtG5yjex4ms/g=</HostId>
</Error>

I already checked, and the content type is correctly put to image/png . Clearly, I should have access, as I was the one putting the images in the first place, and the fact that I can download the image successfully is confirmation. Why can't I use the link to display those images?

2 Answers
1

If you would like to preview the image from S3, you can do so by clicking the "Open" button.

Object view with the Open button outlined in red

I have tested this with an image, the Content-Type is system-defined to image/png and the user role had a policy with two actions s3:GetObject, s3:ListBucket. Note that opening an image directly from the "Object URL" is not the same as clicking the "Open" button.

answered 2 years ago

EXPERT

reviewed 2 years ago

0

Hello.

Are you trying to display the image in the browser using the object URL?
In that case, if you are accessing S3 directly, you will need to disable all public access blocks and set the appropriate bucket policy.
Public access block settings have account level settings and bucket level settings, so please disable both.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/configuring-block-public-access-account.html
https://docs.aws.amazon.com/AmazonS3/latest/userguide/configuring-block-public-access-bucket.html

Try using the following bucket policy:

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

In addition to the above, you can also use CloudFront to distribute images in S3, so please check the settings in the document below.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.