Skip to content

Instantly share code, notes, and snippets.

@marcosgabarda
Last active August 29, 2015 14:04
Show Gist options
  • Save marcosgabarda/6f2d002be66002fd5e10 to your computer and use it in GitHub Desktop.
Save marcosgabarda/6f2d002be66002fd5e10 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""Storages for split media and static in different folders."""
import storages.backends.s3boto
class StaticRootS3BotoStorage(storages.backends.s3boto.S3BotoStorage):
"""Storage for save all static files in static folder."""
def __init__(self, *args, **kwargs):
"""Overrides and define location in "static".
@param args:
@param kwargs:
"""
kwargs['location'] = "static"
super(StaticRootS3BotoStorage, self).__init__(*args, **kwargs)
class MediaRootS3BotoStorage(storages.backends.s3boto.S3BotoStorage):
"""Storage for save all media files in media folder."""
def __init__(self, *args, **kwargs):
"""Overrides and define location in "media".
@param args:
@param kwargs:
"""
kwargs['location'] = "media"
super(MediaRootS3BotoStorage, self).__init__(*args, **kwargs)
########### STORAGES CONFIGURATION
AWS_ACCESS_KEY_ID = get_env_setting('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = get_env_setting('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = get_env_setting('AWS_STORAGE_BUCKET_NAME')
AWS_QUERYSTRING_AUTH = False
DEFAULT_FILE_STORAGE = 'core.s3utils.MediaRootS3BotoStorage'
MEDIA_URL = "//{}.s3.amazonaws.com/media/".format(AWS_STORAGE_BUCKET_NAME)
STATICFILES_STORAGE = 'core.s3utils.StaticRootS3BotoStorage'
STATIC_URL = "//{}.s3.amazonaws.com/static/".format(AWS_STORAGE_BUCKET_NAME)
########### END STORAGES CONFIGURATION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment