summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/uploads.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/core/uploads.py b/core/uploads.py
new file mode 100644
index 0000000..ef235f0
--- /dev/null
+++ b/core/uploads.py
@@ -0,0 +1,15 @@
+import base64
+import os
+import uuid
+
+from django.utils import timezone
+
+
+def upload_namer(prefix, instance, filename):
+ """
+ Names uploaded images, obscuring their original name with a random UUID.
+ """
+ now = timezone.now()
+ _, old_extension = os.path.splitext(filename)
+ new_filename = base64.b32encode(uuid.uuid4().bytes).decode("ascii")
+ return f"{prefix}/{now.year}/{now.month}/{now.day}/{new_filename}{old_extension}"