Skip to content

Commit

Permalink
[fix] optimize file upload process
Browse files Browse the repository at this point in the history
  • Loading branch information
yxzlwz committed Jan 5, 2025
1 parent d1d001a commit e597bce
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/cloudreve/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e597bce

Please sign in to comment.