Protecting some file storage
Most of your media downloads are user avatars, for example, you want to be public. But if you have media that requires authentication before you can access it - say, a PDF summary that only members can access, then you donβt want S3BotoStorages to have a public S3 ACL by default. Here we do not need a subclass, because we can pass an instance, and not refer to the class.
so first remove protection for all file fields in your settings and add cache control
AWS_HEADERS = { 'Cache-Control': 'max-age=86400', }
Then make the desired protected field to use your protected path
from django.db import models import storages.backends.s3boto protected_storage = storages.backends.s3boto.S3BotoStorage( acl='private', querystring_auth=True, querystring_expire=600,
But you also need to use your regular storage when you are in dev, and usually you use local storage, so I personally communicated with it
if settings.DEFAULT_FILE_STORAGE == 'django.core.files.storage.FileSystemStorage': protected_storage = FileSystemStorage() logger.debug('Using FileSystemStorage for resumes files') else: protected_storage = S3BotoStorage( acl='private', querystring_auth=True, querystring_expire=86400,
REF: https://tartarus.org/james/diary/2013/07/18/fun-with-django-storage-backends
source share