Hello fellowes,
I am discovering new Django 4.2 storages settings. I want to have a main file system (default) then I would like to customise media folder on top of it (add media subfolder to all uploaded files and public-read ACL).
Before, I would have made a custom storage class inheriting of S3Boto… But it doesn’t work anymore (myabe I am doing something wrong).
I’ve endup doing below code but I don’t find that elegant.
Do you see another way to do it ?
DEFAULT_S3_STORAGE_OPTIONS = {
"access_key": env.str("OVH_ACCESS_KEY"),
"secret_key": env.str("OVH_SECRET_KEY"),
"bucket_name": env.str("BUCKET_NAME"),
"region_name": env.str("BUCKET_REGION"),
"endpoint_url": "https://s3.gra.io.cloud.ovh.net",
"custom_domain": f"{env.str('BUCKET_NAME')}.s3.gra.io.cloud.ovh.net",
}
STORAGES = {
"default": {
"BACKEND": "storages.backends.s3.S3Storage",
"OPTIONS": {
**DEFAULT_S3_STORAGE_OPTIONS,
},
},
"public_media": {
"BACKEND": "storages.backends.s3.S3Storage",
"OPTIONS": {
**DEFAULT_S3_STORAGE_OPTIONS,
"location": "media",
"default_acl": "public-read",
"file_overwrite": True,
"querystring_auth": False,
},
},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}
++
Swann