Skip to content

Commit

Permalink
fix: Fix chunked upload
Browse files Browse the repository at this point in the history
Closes: SDK-1974
Fixes: #671
  • Loading branch information
lukaszsocha2 committed Feb 3, 2022
1 parent 928d4c3 commit 094cc9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
9 changes: 5 additions & 4 deletions boxsdk/object/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def create_upload_session(self, file_size: int, file_name: Optional[str] = None)

@api_call
def get_chunked_uploader(self, file_path: str, rename_file: bool = False) -> 'ChunkedUploader':
# pylint: disable=consider-using-with
"""
Instantiate the chunked upload instance and create upload session with path to file.
Expand All @@ -82,10 +83,10 @@ def get_chunked_uploader(self, file_path: str, rename_file: bool = False) -> 'Ch
A :class:`ChunkedUploader` object.
"""
total_size = os.stat(file_path).st_size
with open(file_path, 'rb') as content_stream:
file_name = os.path.basename(file_path) if rename_file else None
upload_session = self.create_upload_session(total_size, file_name)
return upload_session.get_chunked_uploader_for_stream(content_stream, total_size)
content_stream = open(file_path, 'rb')
file_name = os.path.basename(file_path) if rename_file else None
upload_session = self.create_upload_session(total_size, file_name)
return upload_session.get_chunked_uploader_for_stream(content_stream, total_size)

def _get_accelerator_upload_url_for_update(self) -> Optional[str]:
"""
Expand Down
9 changes: 5 additions & 4 deletions boxsdk/object/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def create_upload_session(self, file_size: int, file_name: str) -> 'UploadSessio

@api_call
def get_chunked_uploader(self, file_path: str) -> 'ChunkedUploader':
# pylint: disable=consider-using-with
"""
Instantiate the chunked upload instance and create upload session with path to file.
Expand All @@ -146,10 +147,10 @@ def get_chunked_uploader(self, file_path: str) -> 'ChunkedUploader':
A :class:`ChunkedUploader` object.
"""
total_size = os.stat(file_path).st_size
with open(file_path, 'rb') as content_stream:
file_name = os.path.basename(file_path)
upload_session = self.create_upload_session(total_size, file_name)
return upload_session.get_chunked_uploader_for_stream(content_stream, total_size)
content_stream = open(file_path, 'rb')
file_name = os.path.basename(file_path)
upload_session = self.create_upload_session(total_size, file_name)
return upload_session.get_chunked_uploader_for_stream(content_stream, total_size)

def _get_accelerator_upload_url_fow_new_uploads(self) -> Optional[str]:
"""
Expand Down
11 changes: 6 additions & 5 deletions boxsdk/object/upload_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def get_chunked_uploader_for_stream(self, content_stream: IO[bytes], file_size:
return ChunkedUploader(self, content_stream, file_size)

def get_chunked_uploader(self, file_path: str) -> ChunkedUploader:
# pylint: disable=consider-using-with
"""
Instantiate the chunked upload instance and create upload session with path to file.
Expand All @@ -171,8 +172,8 @@ def get_chunked_uploader(self, file_path: str) -> ChunkedUploader:
A :class:`ChunkedUploader` object.
"""
total_size = os.stat(file_path).st_size
with open(file_path, 'rb') as content_stream:
return self.get_chunked_uploader_for_stream(
content_stream=content_stream,
file_size=total_size,
)
content_stream = open(file_path, 'rb')
return self.get_chunked_uploader_for_stream(
content_stream=content_stream,
file_size=total_size,
)

0 comments on commit 094cc9b

Please sign in to comment.