I am making a website which accepts video and then the video is converted into bytes
and then I store it in database after converting with io.BytesIO()
function.
It took me a long time (approx. 20-30sec) for just saving a 30 sec video (approx. 18-20mb video file).
I am using Deta Drive for database for saving the videos which is a non-asynchronous.
Note : I want to save the videos in database only not in file.
My Code
app.py
@app.post("", response_description="Post data added into the database")
async def create_post(data: PostsSchema = Depends(), video: UploadFile = File(default=None), background_tasks: BackgroundTasks = BackgroundTasks()):
data = data.dict()
if not video:
video_data = None
else:
video.filename = f"{data['postid']}.mp4"
video_contents = await video.read()
data = jsonable_encoder(data)
data["created_at"] = datetime.strftime(datetime.now(), "%Y-%d-%m %H:%M:%S")
data["video"] = video_data
background_tasks.add_task(add_post, post_data=data)
return ResponseModel('Success', 'Post created!')
database.py
video_database = deta.Drive("video")
async def add_post(post_data : dict):
if post_data["is_video_post"]:
post = video_database.put(name='some_name.mp4', data=io.BytesIO(post_data["video"]), content_type="video/mp4")
post = await post_database.put(data=post_data, key=some_key)
new_post = await post_database.get(key=some_key)
return post_helper(new_post)
Please help me with this problem...
I am expecting it to be fast as much as possible.