Created
April 24, 2018 17:56
-
-
Save iMerica/051cfd1f21284d5eeab49d27a3f9faeb to your computer and use it in GitHub Desktop.
Django Static Asset Versioning and Auto-Upload to S3/Cloudfront
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from storages.backends.s3boto3 import S3Boto3Storage | |
from django.contrib.staticfiles.storage import ManifestFilesMixin | |
from tempfile import SpooledTemporaryFile | |
import os | |
class CustomStorage(ManifestFilesMixin, S3Boto3Storage): | |
""" Handles File Versioning + File Uploading to our CDN """ | |
def _save_content(self, obj, content, parameters): | |
""" Hack to work around I/O error in Boto """ | |
content.seek(0, os.SEEK_SET) | |
content_autoclose = SpooledTemporaryFile() | |
content_autoclose.write(content.read()) | |
super(CustomStorage, self)._save_content(obj, content_autoclose, parameters) | |
if not content_autoclose.closed: | |
content_autoclose.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your Django settings, set: