Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
S3BotoStorage subclass for media and static buckets
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = 'path.to.storage.S3StaticStorage'
THUMBNAIL_DEFAULT_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = 'YOUR KEY'
AWS_SECRET_ACCESS_KEY = 'YOUR KEY'
AWS_STORAGE_BUCKET_NAME = 'media.YOURSITE.com'
AWS_STATIC_BUCKET_NAME = 'static.YOURSITE.com'
AWS_S3_CUSTOM_DOMAIN = AWS_STORAGE_BUCKET_NAME
AWS_STATIC_CUSTOM_DOMAIN = AWS_STATIC_BUCKET_NAME
STATIC_URL = 'http://%s/' % AWS_STATIC_BUCKET_NAME
MEDIA_URL = 'http://%s/' % AWS_STORAGE_BUCKET_NAME
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)
@jamstooks

This comment has been minimized.

Show comment Hide comment
@jamstooks

jamstooks Jun 29, 2012

Thanks, Dude! This was handy. I extended it to use different locations (/static/ and /media/), instead of domains, but same concept and this helped...

Thanks, Dude! This was handy. I extended it to use different locations (/static/ and /media/), instead of domains, but same concept and this helped...

@richleland

This comment has been minimized.

Show comment Hide comment
@richleland

richleland Jun 30, 2012

No prob - glad it helped you out!

Owner

richleland commented Jun 30, 2012

No prob - glad it helped you out!

@nkeilar

This comment has been minimized.

Show comment Hide comment
@nkeilar

nkeilar Mar 21, 2013

Unless Im mistaken this just uses two buckets, not mapping onto the one which IMHO is more desirable.

nkeilar commented Mar 21, 2013

Unless Im mistaken this just uses two buckets, not mapping onto the one which IMHO is more desirable.

@richleland

This comment has been minimized.

Show comment Hide comment
@richleland

richleland Apr 11, 2013

@madteckhead yep you're right. The purpose of this gist was to allow two separate buckets for media and static. If you only set DEFAULT_FILE_STORAGE it will do the behavior you mention by default.

Owner

richleland commented Apr 11, 2013

@madteckhead yep you're right. The purpose of this gist was to allow two separate buckets for media and static. If you only set DEFAULT_FILE_STORAGE it will do the behavior you mention by default.

@abhillman

This comment has been minimized.

Show comment Hide comment
@abhillman

abhillman Nov 21, 2013

Is there a good way to migrate existing media to S3—something similar to ./manage collectstatic?

Is there a good way to migrate existing media to S3—something similar to ./manage collectstatic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment