0

I tried to put my app online, but it seems that image files don't show up. Maybe you can help? I have required images in my bucket in S3 AWS, but still nothing appears. Although when I try to open the image on the webside I am sent to the amazon website. And tehn I get this message:

InvalidRequest The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256. 8CF0C70490DEFEE2 dtBKlPBbw5L6pM6mGyd4YaqC4amay/c2tccfhhStjujVGG2qdrvQwD6vGloJZWQle9A5Cwr3Rws=

Here is my settings.py

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_TMP = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

os.makedirs(STATIC_TMP, exist_ok=True)

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

AWS_ACCESS_KEY_ID = "####"
AWS_SECRET_ACCESS_KEY="####"
AWS_STORAGE_BUCKET_NAME="####"

AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

django_heroku.settings(locals())

1 Answer 1

1

Your MEDIA_URL is not correct.

Try something like this (I am assuming you want you use for static resources and media):

AWS_AUTO_CREATE_BUCKET = True
AWS_STORAGE_BUCKET_NAME = "my_bucket"

DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"

STATIC_LOCATION = "resources/"
MEDIA_LOCATION = "media/"

AWS_BUCKET_ACL = "public-read"
AWS_QUERYSTRING_AUTH = False
AWS_S3_REGION_NAME = "your-bucket-region"

AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com"


STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/{STATIC_LOCATION}"
MEDIA_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/{MEDIA_LOCATION}/"
Sign up to request clarification or add additional context in comments.

8 Comments

Hi, thanks for answer, but here is a repetition. You wrote two times STATIC_URL and MEDIA_URL. Can you correct this?
Ok, now I got this message, when I try to access image <Error> <Code>AccessDenied</Code> <Message>Access Denied</Message> <RequestId>A868FC94C6274D47</RequestId> <HostId> KSDU9jrCp3Gwlo4sGb0YIcS5xgZe39FLQRcwwW9691LokMLOUWTnz0fT6qyLkYy799HbieSRFV8= </HostId> </Error>
oh sorry. There you go.
It is probably something with your bucket access. Make sure that the credentials you are using have access to the bucket, and the bucket cors are correctly set.
Hmm... I believe I did it right. Please tell me. AWS_S3_REGION_NAME = us-eas-2 is it how it supposed to be written?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.