mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
18 lines
521 B
Python
18 lines
521 B
Python
import os
|
|
|
|
|
|
async def upload_video(video_file, activity_id):
|
|
contents = video_file.file.read()
|
|
video_format = video_file.filename.split(".")[-1]
|
|
# create folder
|
|
os.mkdir(f"content/uploads/video/{activity_id}")
|
|
|
|
try:
|
|
with open(f"content/uploads/video/{activity_id}/video.{video_format}", 'wb') as f:
|
|
f.write(contents)
|
|
f.close()
|
|
|
|
except Exception as e:
|
|
return {"message": "There was an error uploading the file"}
|
|
finally:
|
|
video_file.file.close()
|