Images are not loading from an Amazon S3 bucket

Viewed 2212

I am doing a Django project. I have hosted my static files on Amazon S3. It has been successfully uploaded to it. But, the images are not loading when I run the server. When I inspect the image field it shows: https://django-ecommerce-files.s3.amazonaws.com/images/logo.png%22%20id=%22image%22%20style=%22width:%2040px;%20height:40px%22%3E When I double clicked it. It shows this error:

<Error>
  <Code>AccessDenied</Code>
  <Message>Access Denied</Message>
  <RequestId>07PX6KHYASHT3008</RequestId>
  <HostId>pJCxChq1JHlw/GL0Zy/W+PvX1TevOf/C60Huyidi8+0GMAs8geYlXSrEgo6m9vllL0PouTn6NAA= 
  </HostId>
</Error>
3 Answers

When working with S3 bucket, there is a need to make your resources(files) publicly accessible. You can either do that programmatically at the point of uploading to S3 or from the AWS console. please check how you can enable public access to your files here

Make sure that you have changed the public access settings for the S3 bucket, such that it allows files to be accessed by your app (with the right credentials).

Your requirement may vary, so take a look at their user manual.

Check the Permissions tab under the bucket.

Or, you can also take a look at the actions allowed on your S3 bucket, it must be configured to allow read/write. Refer the docs for a few examples

im not sure if this works. can you try enabling the static hosting on your s3?

  1. go to your s3.
  2. go to properties, scroll down to the bottom
  3. enable the static hosting

a png file on s3 would look like this(the link works btw):

https://aws-cicd-react.s3.ap-southeast-1.amazonaws.com/logo512.png

addendum: if you want to see the url of your file:

  1. In your s3, click the file then go to properties
  2. look at the Object URL enter image description here
Related