Django на Heroku не загружает медиа на S3

Я работаю над проектом, используя Django(3), в котором я хочу загружать статические файлы в ведро S3, используя boto3

.

Здесь setttings.py:

if USE_S3:
    # aws settings
    AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
    AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
    AWS_DEFAULT_ACL = 'public-read'
    AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
    AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
    # s3 static settings
    AWS_LOCATION = 'static'
    STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{AWS_LOCATION}/'
    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
    # STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
else:
    STATIC_URL = '/assets/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

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


django_on_heroku.settings(locals())
options = DATABASES['default'].get('OPTIONS', {})
options.pop('sslmode', None)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

My site is loading correctly and while deployment collectstatic copied all files to S3 bucket but now if I upload a file from django admin, its not uploading to S3 bucket, there's wasn't any mediafiles folder in the bucket, so I manually created that directly but files are not uploading there.

Вернуться на верх