Hiddenguy
Hiddenguy

Reputation: 537

Heroku + S3 AWS + Django != No Images

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())

Upvotes: 0

Views: 383

Answers (1)

Stargazer
Stargazer

Reputation: 1530

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}/"

Upvotes: 1

Related Questions