19 lines
595 B
Python
19 lines
595 B
Python
import random
|
|
import string
|
|
import os
|
|
import shutil
|
|
|
|
def UploadFile(file, filename, content_type):
|
|
def randmname(size=6, chars=string.ascii_lowercase + string.digits):
|
|
return ''.join(random.choice(chars) for _ in range(size))
|
|
split_filename = filename.split('.')
|
|
rand_filename = f"{randmname(25)}.{split_filename[1]}"
|
|
|
|
with open(f'files/{rand_filename}','wb',100*(2**20)) as buffer:
|
|
shutil.copyfileobj(file.file, buffer)
|
|
|
|
cdn_info = {
|
|
"url" : f"https://cdn.oki.cx/files/{rand_filename}",
|
|
"content_type" : content_type
|
|
}
|
|
return cdn_info |