From f5eafb0ca0af3ed064202abbe99bfbeef8bbb74d Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 17 Nov 2022 08:21:42 -0700 Subject: Add image/icon upload --- core/uploads.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 core/uploads.py (limited to 'core') 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}" -- cgit v1.2.3