init
This commit is contained in:
19
models.py
Normal file
19
models.py
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
Reference in New Issue
Block a user