This repository has been archived on 2023-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
takahe/core/uploads.py
2022-12-03 14:07:30 -07:00

15 lines
407 B
Python

import os
import secrets
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 = secrets.token_urlsafe(20)
return f"{prefix}/{now.year}/{now.month}/{now.day}/{new_filename}{old_extension}"