Last active
August 29, 2015 14:04
-
-
Save darthwade/0f00744af166d5954aa1 to your computer and use it in GitHub Desktop.
S3BotoStorage subclass for media and static buckets.
This file contains 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
from __future__ import unicode_literals | |
import os | |
from boto.s3.connection import SubdomainCallingFormat | |
# AWS S3 | |
AWS_S3_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID') | |
AWS_S3_SECRET_ACCESS_KEY = os.getenv('AWS_S3_SECRET_ACCESS_KEY') | |
AWS_S3_BASE_URL = 's3.amazonaws.com' | |
# AWS_S3_FILE_BUFFER_SIZE = 5242880 | |
# AWS_S3_FILE_OVERWRITE = True | |
# AWS_HEADERS = {} | |
# AWS_AUTO_CREATE_BUCKET = False | |
AWS_DEFAULT_ACL = 'public-read' | |
AWS_BUCKET_ACL = AWS_DEFAULT_ACL | |
# AWS_QUERYSTRING_AUTH = True | |
# AWS_QUERYSTRING_EXPIRE = 3600 | |
# AWS_REDUCED_REDUNDANCY = False | |
# AWS_LOCATION = '' | |
# AWS_S3_ENCRYPTION = False | |
# AWS_S3_CUSTOM_DOMAIN = None | |
# AWS_S3_CALLING_FORMAT = SubdomainCallingFormat() | |
# AWS_S3_SECURE_URLS = True | |
# AWS_S3_FILE_NAME_CHARSET = 'utf-8' | |
# AWS_PRELOAD_METADATA = False | |
AWS_S3_URL_PROTOCOL = 'http:' | |
AWS_IS_GZIPPED = True | |
GZIP_CONTENT_TYPES = ( | |
'text/css', | |
'application/javascript', | |
'application/x-javascript', | |
) | |
# Media | |
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' | |
AWS_STORAGE_BUCKET_NAME = 'media.site.com' | |
# AWS_S3_CUSTOM_DOMAIN = AWS_STORAGE_BUCKET_NAME | |
MEDIA_URL = '%s//%s.%s/' % (AWS_S3_URL_PROTOCOL, AWS_STORAGE_BUCKET_NAME, AWS_S3_BASE_URL) | |
# Static | |
STATICFILES_STORAGE = 'path.to.storage.S3StaticStorage' | |
AWS_STATIC_BUCKET_NAME = 'static.site.com' | |
# AWS_STATIC_CUSTOM_DOMAIN = AWS_STATIC_BUCKET_NAME | |
STATIC_URL = '%s//%s.%s/' % (AWS_S3_URL_PROTOCOL, AWS_STATIC_BUCKET_NAME, AWS_S3_BASE_URL) | |
STATICFILES_DIRS = ( | |
os.path.join(BASE_DIR, 'static'), | |
) | |
STATICFILES_FINDERS = ( | |
'django.contrib.staticfiles.finders.FileSystemFinder', | |
'django.contrib.staticfiles.finders.AppDirectoriesFinder', | |
) |
This file contains 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
from django.conf import settings | |
from storages.backends.s3boto import S3BotoStorage | |
class S3StaticStorage(S3BotoStorage): | |
"S3 storage backend that sets the static bucket." | |
def __init__(self, *args, **kwargs): | |
super(S3StaticStorage, self).__init__(bucket=settings.AWS_STATIC_BUCKET_NAME, | |
custom_domain=settings.AWS_STATIC_CUSTOM_DOMAIN, | |
*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment