mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: backend create & upload video
This commit is contained in:
parent
cc9397ca5f
commit
42d74aebde
8 changed files with 103 additions and 15 deletions
|
|
@ -1,12 +1,33 @@
|
|||
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()
|
||||
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()
|
||||
|
||||
# create folder
|
||||
os.mkdir(f"content/uploads/video/{element_id}")
|
||||
|
||||
try:
|
||||
with open(f"content/uploads/video/{element_id}/{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:
|
||||
video_file.file.close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue