Integrate with django's custom file storage settings
WhyNotHugo opened this issue · 1 comments
WhyNotHugo commented
We currently use a few custom settings (e.g.: AFIP_KEY_STORAGE
, AFIP_CERT_STORAGE
) to define storages.
Django 4.2 implements a standard mechanism for defining custom storages. We should move over to use that.
See: https://docs.djangoproject.com/en/4.2/releases/4.2/#custom-file-storages
spuigdengolas commented
One example of custom storage backend could be the following. This setting makes files uploaded to S3 private.
storages.py
from django.core.files.storage import get_storage_class
from storages.backends.s3boto3 import S3Boto3Storage
class PrivateMediaStorage(S3Boto3Storage):
location = "media/private"
default_acl = "private"
file_overwrite = False
custom_domain = False
def __init__(self):
super().__init__()
self.bucket_name = settings.AWS_PRIVATE_STORAGE_BUCKET_NAME
def select_private_storage():
# important
private_storage_class = get_storage_class(settings.PRIVATE_FILE_STORAGE)
return private_storage_class() # instantiate the storage
production.py
PRIVATE_FILE_STORAGE = "my_project.utils.storages.PrivateMediaStorage"
AFIP_PDF_STORAGE = PRIVATE_FILE_STORAGE