How do I make media files display automatically in django using s3 as storage?

Lord_Sarcastic

I configured my s3 settings like so:

DEFAULT_FILE_STORAGE = 'Bonychicken.storage_backends.MediaStorage'
AWS_STORAGE_BUCKET_NAME = 'bonychicken'
AWS_S3_REGION_NAME = 'us-east-2'
AWS_ACCESS_KEY_ID = '<my access key id>'
AWS_SECRET_ACCESS_KEY = '<my secret access key>'
AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.{AWS_S3_REGION_NAME}.amazonaws.com"
AWS_QUERYSTRING_AUTH = False
AWS_DEFAULT_ACL = None
STATIC_URL = '/static/'
MEDIAFILES_LOCATION = 'media'
MEDIA_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/media/"
MEDIA_ROOT = f"https://{AWS_S3_CUSTOM_DOMAIN}/media/"
AWS_IS_GZIPPED = True
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}

My storage class is:

from storages.backends.s3boto3 import S3Boto3Storage

class MediaStorage(S3Boto3Storage):
    bucket_name = 'bonychicken'
    location = 'media'
    file_overwrite = False

I added storages to my installed apps and boto3 is also installed.

CORS Configuration is:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>

block public access has been turned off. IAM user has permissions to the bucket.

The problem is, whenever I upload a file, it is uploaded to my s3 bucket but it doesn't show on the html page. Trying to access the image url from the source code yields:

<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <RequestId><random letters here></RequestId>
    <HostId>
        <random letters here>
    </HostId>
</Error>

But if I go to my bucket settings and select actions and click on make public after marking the media files, everything starts working. This means for each image uploaded, I have to mark and repeat over and over again.

How do I solve this?

Bernardo Duarte

I think that you should change the default ACL in your AWS settings as shown in the docs.

Just set the AWS_DEFAULT_ACL to AWS_DEFAULT_ACL='public-read'.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do I list unsynced files on a removable media?

분류에서Dev

How do I make to start docker automatically after reboots?

분류에서Dev

when unloading a table from amazon redshift to s3, how do I make it generate only one file

분류에서Dev

How do I make a relative path for header files in QMAKE

분류에서Dev

How do I make rsync skip files that failed to transfer?

분류에서Dev

How do I use external python utility files in a Django project?

분류에서Dev

Using an array, how do I store and display the unique numbers?

분류에서Dev

UbuntuGNOME uses other nautilus, how do I make it split the window into two using F3

분류에서Dev

How do i make my fragment using a viewPager

분류에서Dev

How do I display url

분류에서Dev

How can I make ACL settings on /run/media/* persistent?

분류에서Dev

Using PyCharm Professional and Vagrant, how do I run a Django server?

분류에서Dev

Sometimes it's convenient to use ` read -t 3 ` instead of ` sleep 3 `. How do I make it work with `nohup`?

분류에서Dev

How can I have an application automatically display on all desktops with openbox?

분류에서Dev

How do I make files copied over the network from my Windows computer be owned by me?

분류에서Dev

How do I make a button handle it's on OnClick event?

분류에서Dev

How do I make sure I am using the latest java libraries in my projects?

분류에서Dev

How can I send SMS from my PC using my Android Phone (Galaxy S3)

분류에서Dev

How do I display a user control registered by path in main window using Castle (WPF)

분류에서Dev

How do I build up an html string to display within a div using razor mvc?

분류에서Dev

How do I display millisecond in my stopwatch?

분류에서Dev

How do I display the whole line of text?

분류에서Dev

How to automatically switch off default display and set resolution if I connect a specific display?

분류에서Dev

How do I make a dictionary of OD pairs from a distance Matrix using python?

분류에서Dev

How do I make variable in for loop bigger that in was

분류에서Dev

How do I make a "for" loop for this sequence of arrays?

분류에서Dev

How do I make a decorator typesafe in TypeScript?

분류에서Dev

How do I make a Range reverse on condition?

분류에서Dev

How do I make a border padding for a UITextField?

Related 관련 기사

  1. 1

    How do I list unsynced files on a removable media?

  2. 2

    How do I make to start docker automatically after reboots?

  3. 3

    when unloading a table from amazon redshift to s3, how do I make it generate only one file

  4. 4

    How do I make a relative path for header files in QMAKE

  5. 5

    How do I make rsync skip files that failed to transfer?

  6. 6

    How do I use external python utility files in a Django project?

  7. 7

    Using an array, how do I store and display the unique numbers?

  8. 8

    UbuntuGNOME uses other nautilus, how do I make it split the window into two using F3

  9. 9

    How do i make my fragment using a viewPager

  10. 10

    How do I display url

  11. 11

    How can I make ACL settings on /run/media/* persistent?

  12. 12

    Using PyCharm Professional and Vagrant, how do I run a Django server?

  13. 13

    Sometimes it's convenient to use ` read -t 3 ` instead of ` sleep 3 `. How do I make it work with `nohup`?

  14. 14

    How can I have an application automatically display on all desktops with openbox?

  15. 15

    How do I make files copied over the network from my Windows computer be owned by me?

  16. 16

    How do I make a button handle it's on OnClick event?

  17. 17

    How do I make sure I am using the latest java libraries in my projects?

  18. 18

    How can I send SMS from my PC using my Android Phone (Galaxy S3)

  19. 19

    How do I display a user control registered by path in main window using Castle (WPF)

  20. 20

    How do I build up an html string to display within a div using razor mvc?

  21. 21

    How do I display millisecond in my stopwatch?

  22. 22

    How do I display the whole line of text?

  23. 23

    How to automatically switch off default display and set resolution if I connect a specific display?

  24. 24

    How do I make a dictionary of OD pairs from a distance Matrix using python?

  25. 25

    How do I make variable in for loop bigger that in was

  26. 26

    How do I make a "for" loop for this sequence of arrays?

  27. 27

    How do I make a decorator typesafe in TypeScript?

  28. 28

    How do I make a Range reverse on condition?

  29. 29

    How do I make a border padding for a UITextField?

뜨겁다태그

보관