From e597bce2da228456fb24897cbc2bb80317c3a640 Mon Sep 17 00:00:00 2001 From: yxzlwz Date: Sun, 5 Jan 2025 10:23:47 +0800 Subject: [PATCH] [fix] optimize file upload process --- src/cloudreve/models.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/cloudreve/models.py b/src/cloudreve/models.py index 99f19a5..8f3bdbe 100644 --- a/src/cloudreve/models.py +++ b/src/cloudreve/models.py @@ -343,15 +343,23 @@ def create_dir(self, dir_path): def upload_to_local(self, local_file: Path, sessionID, chunkSize, expires): with open(local_file, 'rb') as file: - file_data = file.read() - self.request( - 'post', - f'/file/upload/{sessionID}/0', - headers={ - 'Content-Type': 'application/octet-stream', - }, - data=file_data, - ) + block_id = 0 + while True: + chunk = file.read(chunkSize) + if not chunk: + break + + self.request( + 'post', + f'/file/upload/{sessionID}/{block_id}', + headers={ + 'Content-Length': str(len(chunk)), + 'Content-Type': 'application/octet-stream', + }, + data=chunk, + ) + + block_id += 1 def upload_to_onedrive(self, local_file: Path, sessionID, chunkSize, expires, uploadURLs):