2

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>
smac2020
  • 9,637
  • 4
  • 24
  • 38
Arun George
  • 33
  • 1
  • 4

3 Answers3

3

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

Hassan Liasu
  • 101
  • 3
  • 7
  • It worked for the static files. But, whenever I added a new image from the system, it doesn't load. Is there any way to solve this? – Arun George Sep 21 '21 at 07:25
  • 1
    is it still the same permission/access issue? – Hassan Liasu Sep 21 '21 at 07:37
  • No. It says "the server responded with a status of 400 (Bad Request)". It shows this error: InvalidRequest The authorization mechanism you have provided is not supported .Please use AWS4-HMAC-SHA256. 19KCKVYHY43FT2AJ +VcQe1t1iuS8by3C2cESj4yXNszpqUfk8NQWbnkhEtXRQO8YYJxg7rt3nPaibHQEvgYAxBcbZ8Y= – Arun George Sep 21 '21 at 08:15
  • okay. please refer to this https://stackoverflow.com/questions/26533245/the-authorization-mechanism-you-have-provided-is-not-supported-please-use-aws4 – Hassan Liasu Sep 21 '21 at 08:40
  • Thank you so much .One of the solution in the above link helped me to clear the error. Now, everything works fine. – Arun George Sep 21 '21 at 09:33
  • Enjoy! Happy coding ☺️ – Hassan Liasu Sep 21 '21 at 13:24
2

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

Rajat M
  • 31
  • 1
  • 4
1

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