Last active
June 6, 2019 20:17
-
-
Save diegosorrilha/aebcaf146c83da7ac20e7292032db3f8 to your computer and use it in GitHub Desktop.
Django + S3 Storage Configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# STORAGE CONFIGURATION IN S3 AWS | |
AWS_ACCESS_KEY_ID= | |
AWS_SECRET_ACCESS_KEY= | |
AWS_STORAGE_BUCKET_NAME= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipenv install django-s3-folder-storage | |
#or | |
pip install django-s3-folder-storage | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID') | |
# STORAGE CONFIGURATION IN S3 AWS | |
# ------------------------------------------------------------------------------ | |
if AWS_ACCESS_KEY_ID: | |
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY') | |
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME') | |
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400', } | |
AWS_PRELOAD_METADATA = True | |
AWS_AUTO_CREATE_BUCKET = False | |
AWS_QUERYSTRING_AUTH = False | |
AWS_S3_CUSTOM_DOMAIN = None | |
AWS_DEFAULT_ACL = 'private' | |
# Static Assets | |
# ------------------------------------------------------------------------------ | |
STATICFILES_STORAGE = 's3_folder_storage.s3.StaticStorage' | |
STATIC_S3_PATH = 'static' | |
STATIC_ROOT = f'/{STATIC_S3_PATH}/' | |
STATIC_URL = f'//s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/{STATIC_S3_PATH}/' | |
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/' | |
# Upload Media Folder | |
DEFAULT_FILE_STORAGE = 's3_folder_storage.s3.DefaultStorage' | |
DEFAULT_S3_PATH = 'media' | |
MEDIA_ROOT = f'/{DEFAULT_S3_PATH}/' | |
MEDIA_URL = f'//s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/{DEFAULT_S3_PATH}/' | |
INSTALLED_APPS.append('s3_folder_storage') | |
INSTALLED_APPS.append('storages') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment