New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you send gzipped files to S3? django-storages 1.1.6? #368
Comments
same issue here, my files on s3 are 0KB, with gzip. AWS_IS_GZIPPED = True |
I'm also having issues, but i can't identify exactly where the problem is yet. |
@bedspax @kcharvey Did you guys figure out a solution? |
No dude @madteckhead |
Not yet, was planning on addressing it in my deployment scripts outside of django_compressor @madteckhead |
@madteckhead @bedspax @kcharvey Seems to work for me with sekizai and |
When using
|
I fixed this problem this way: The problem is use the same [parameter content] to save local and to upload to S3. Because when we passing the parameter content to super(CachedS3BotoStorage, self).save(name, content), internally the parameter content is modified, so when passed to next .save _self.local_storage.save(name, content) he is with other state due the conf AWS_IS_GZIPPED, that compress the file inside of content. In settings.py STATICFILES_STORAGE = 'mypackage.s3utils.CachedS3BotoStorage' in mypackage.s3utils.py from storages.backends.s3boto import S3BotoStorage
from compressor.storage import CompressorFileStorage
from django.core.files.storage import get_storage_class
import copy
class CachedS3BotoStorage(S3BotoStorage):
"""
S3 storage backend that saves the files locally, too.
"""
location = 'static'
def __init__(self, *args, **kwargs):
super(CachedS3BotoStorage, self).__init__(*args, **kwargs)
self.local_storage = get_storage_class(
"compressor.storage.CompressorFileStorage")()
def url(self, name):
"""
Fix the problem of dont show the natives images django admin
"""
url = super(CachedS3BotoStorage, self).url(name)
if name.endswith('/') and not url.endswith('/'):
url += '/'
return url
def save(self, name, content):
content2 = copy.copy(content) #-> THE SECRET IS HERE
name = super(CachedS3BotoStorage, self).save(name, content)
self.local_storage._save(name, content2) #-> AND HERE
# print id(content)
# print id(content2)
return name
def get_available_name(self, name):
if self.exists(name):
self.delete(name)
return name |
Thanks @mateuspadua! Your fix worked for me! |
:) |
Can i change the path where my compressed file is getting stored on S3. Right now it is getting stored in a separate folder 'CACHE' in my bucket. How can i make it store inside the static folder of my bucket i.e my_bucket/static/CACHE/ . Please suggest a way out. |
I'm REALLY CLOSE to getting this working with django-storages 1.1.4 with the following settings:
myapp/storage/CachedS3BotoStorage.py is set up as described in Issue 100. I run compress with the following command:
This creates appropriately gzipped files in myapp/static/CACHE, and puts files with the correct name to S3 with the correct CONTENT-ENCODING metadata, but the files on S3 are emtpy (0 KB). I can manually upload these files to S3, reset the metadata and permissions, and everything works.
I noticed that @jezdez had committed a bunch of code to django-storages (much of which dealt with gzipping), so I tried updating mine to 1.1.6. Running the same command produced a hash-named file for every one of my source files, but did not minify or compress them in anyway and did not push any files to S3.
Could this issue be addressed in django-storages 1.1.6? If so, is there any documentation around that? I'd be happy to help update the documentation if someone can point me to the code that will help me figure this out.
The text was updated successfully, but these errors were encountered: