Created
March 19, 2019 01:49
-
-
Save qqpann/1a358f766de4dfec8cbe10635e70490d to your computer and use it in GitHub Desktop.
[Django image upload_to uuid filename snipet] #django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid, os, base64 | |
def uuid32(): | |
return base64.b32encode(uuid.uuid4().bytes).decode('ASCII').rstrip('=') | |
def get_filefield_ascii_uuid(instance, filename): | |
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename> | |
prefix = 'image' | |
name = uuid32() | |
extension = os.path.splitext(filename)[-1] | |
return '{0}/{1}{2}'.format(prefix, name, extension) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment