from random import choices
def random_string(n):
pattern = '1234567890qwertyuiopasdfghjklzxcvbnm'
return ''.join(choices(pattern, k = n))
from os.path import splitext
def random_filename(n, filename):
_, ext = splitext(filename)
return random_string(n - len(ext)) + ext
def upload(f):
filename = random_filename(32, f.name)
with open('./statics/images/{filename}') as desc:
for chunk in f.chunks():
des.write(chunk)
return filename