How is it possible to use django_compressor to send gziped files to Amazon S3?
I tried in several ways but it didn't work. Here is my last settings.py configuration:
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_URL = "http://xxx.cloudfront.net/"
STATIC_URL = COMPRESS_URL
COMPRESS_OUTPUT_DIR = 'CACHE'
#COMPRESS_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
COMPRESS_STORAGE = 'core.storage.CachedS3BotoStorage'
STATICFILES_STORAGE = 'compressor.storage.GzipCompressorFileStorage'
COMPRESS_YUI_BINARY = 'java -jar contrib/yuicompressor-2.4.7/build/yuicompressor-2.4.7.jar'
COMPRESS_YUI_JS_ARGUMENTS = ''
COMPRESS_CSS_FILTERS = ['compressor.filters.yui.YUICSSFilter']
COMPRESS_JS_FILTERS = ['compressor.filters.yui.YUIJSFilter']
COMPRESS_CSS_HASHING_METHOD = 'hash'
and my storage.py
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage
class CachedS3BotoStorage(S3BotoStorage):
"""
S3 storage backend that saves the files locally, too.
"""
def __init__(self, *args, **kwargs):
super(CachedS3BotoStorage, self).__init__(*args, **kwargs)
self.local_storage = get_storage_class(
"compressor.storage.CompressorFileStorage")()
def save(self, name, content):
name = super(CachedS3BotoStorage, self).save(name, content)
self.local_storage._save(name, content)
return name
django-storages S3 storage backend supports gzip. Add to settings.py:
After plenty of days of hard work and research I was finally able to do this.
Basically you need to do a few things:
AWS_IS_GZIPPED = True
S3Connection
class where you override theDefaultHost
variable to your S3 url. Examples3-eu-west-1.amazonaws.com
subdomain.domain.tld
. You need to setAWS_S3_CALLING_FORMAT = 'boto.s3.connection.OrdinaryCallingFormat'
non_gzipped_file_content = content.file
in yourCachedS3BotoStorage
This is the
CachedS3BotoStorage
class you need:Update 2019: it's described in the official documentation
And your settings:
Than you can simply run: