mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
feat: add s3 storage for media
This commit is contained in:
@@ -172,4 +172,31 @@ USE_TZ = True
|
||||
|
||||
STATIC_URL = "static/"
|
||||
MEDIA_URL = "/media/"
|
||||
|
||||
if env.bool("S3_ENABLED", default=False):
|
||||
MEDIA_URL = f"{env('R2_PUBLIC_URL')}/media/"
|
||||
# HACK: S3 auto pre-pends the url scheme forcefully and this prevents double https
|
||||
R2_HOST = env("R2_PUBLIC_URL").replace("https://", "")
|
||||
STORAGES = {
|
||||
"default": {
|
||||
"BACKEND": "storages.backends.s3.S3Storage",
|
||||
"OPTIONS": {
|
||||
"access_key": env("R2_ACCESS_KEY_ID"),
|
||||
"secret_key": env("R2_SECRET_ACCESS_KEY"),
|
||||
"bucket_name": env("R2_STORAGE_BUCKET_NAME"),
|
||||
"region_name": env("R2_REGION_NAME"),
|
||||
"endpoint_url": env("R2_ENDPOINT_URL"),
|
||||
"location": "media",
|
||||
"signature_version": "s3v4",
|
||||
"file_overwrite": False,
|
||||
"custom_domain": R2_HOST,
|
||||
"querystring_auth": False,
|
||||
},
|
||||
},
|
||||
"staticfiles": {
|
||||
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
|
||||
},
|
||||
}
|
||||
DEFAULT_FILE_STORAGE = "storages.backends.s3.S3Storage"
|
||||
|
||||
MEDIA_ROOT = BASE_DIR / "media"
|
||||
|
||||
Reference in New Issue
Block a user