Skip to content

Instantly share code, notes, and snippets.

@andriisoldatenko
Created January 18, 2017 19:26
Show Gist options
  • Save andriisoldatenko/dec7f4e4fa2a54697e0afc65352f92c7 to your computer and use it in GitHub Desktop.
Save andriisoldatenko/dec7f4e4fa2a54697e0afc65352f92c7 to your computer and use it in GitHub Desktop.
from django.core.files.storage import get_storage_class
from storages.backends.s3boto3 import S3Boto3Storage
class StaticS3Boto3Storage(S3Boto3Storage):
file_overwrite = True
class CachedS3BotoStorage(S3Boto3Storage):
"""
S3 storage backend that saves the files locally, too.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.local_storage = get_storage_class(
"django.core.files.storage.FileSystemStorage")()
def save(self, name, content, max_length=None):
name = self.local_storage._save(name, content)
super().save(name, content, max_length=max_length)
return name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment