fix: reformat upload files

This commit is contained in:
swve 2022-12-11 17:09:07 +01:00
parent 88644ad902
commit 805df9b520
6 changed files with 30 additions and 28 deletions

View file

@ -1,33 +0,0 @@
import os
async def upload_thumbnail(thumbnail_file, name_in_disk):
contents = thumbnail_file.file.read()
try:
with open(f"content/uploads/img/{name_in_disk}", 'wb') as f:
f.write(contents)
f.close()
except Exception as e:
print(e)
return {"message": "There was an error uploading the file"}
finally:
thumbnail_file.file.close()
async def upload_video(video_file, name_in_disk, element_id):
contents = video_file.file.read()
video_format = video_file.filename.split(".")[-1]
# create folder
os.mkdir(f"content/uploads/video/{element_id}")
try:
with open(f"content/uploads/video/{element_id}/video.{video_format}", 'wb') as f:
f.write(contents)
f.close()
except Exception as e:
print(e)
return {"message": "There was an error uploading the file"}
finally:
video_file.file.close()