summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorTyler Kennedy2022-12-14 01:26:19 -0500
committerGitHub2022-12-13 23:26:19 -0700
commit0d8b7db2729d94338824c748901637c625c103b0 (patch)
treea431b9990deb11d742dc57e9ccc8b4f77ea6f75a /core
parent3404b155de0c804fd957fd23ded4e241fe885288 (diff)
downloadtakahe-0d8b7db2729d94338824c748901637c625c103b0.tar.gz
takahe-0d8b7db2729d94338824c748901637c625c103b0.tar.bz2
takahe-0d8b7db2729d94338824c748901637c625c103b0.zip
Set the content type and disposition of webp files uploaded to S3
Diffstat (limited to 'core')
-rw-r--r--core/uploads.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/uploads.py b/core/uploads.py
index 0160e2e..c83888c 100644
--- a/core/uploads.py
+++ b/core/uploads.py
@@ -2,6 +2,7 @@ import os
import secrets
from django.utils import timezone
+from storages.backends.s3boto3 import S3Boto3Storage
def upload_namer(prefix, instance, filename):
@@ -12,3 +13,14 @@ def upload_namer(prefix, instance, filename):
_, old_extension = os.path.splitext(filename)
new_filename = secrets.token_urlsafe(20)
return f"{prefix}/{now.year}/{now.month}/{now.day}/{new_filename}{old_extension}"
+
+
+class TakaheS3Storage(S3Boto3Storage):
+ def get_object_parameters(self, name: str):
+ params = self.object_parameters.copy()
+
+ if name.endswith(".webp"):
+ params["ContentDisposition"] = "inline"
+ params["ContentType"] = "image/webp"
+
+ return params