Skip to content

Commit a5b9b14

Browse files
authored
Change S3 Client upload implementation to use upload_fileobj (#115)
1 parent e321e48 commit a5b9b14

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cirro/clients/s3.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ def __init__(self, creds_getter: Callable[[], AWSCredentials], enable_additional
3838
self._upload_args = dict(ChecksumAlgorithm='SHA256') if enable_additional_checksum else dict()
3939
self._download_args = dict(ChecksumMode='ENABLED') if enable_additional_checksum else dict()
4040

41-
def upload_file(self, local_path: Path, bucket: str, key: str):
42-
file_size = local_path.stat().st_size
43-
file_name = local_path.name
41+
def upload_file(self, file_path: Path, bucket: str, key: str):
42+
file_size = file_path.stat().st_size
43+
file_name = file_path.name
4444

4545
with tqdm(total=file_size,
4646
desc=f'Uploading file {file_name} ({convert_size(file_size)})',
4747
bar_format="{desc} | {percentage:.1f}%|{bar:25} | {rate_fmt}",
4848
unit='B', unit_scale=True,
4949
unit_divisor=1024) as progress:
50-
absolute_path = str(local_path.absolute())
51-
self._client.upload_file(absolute_path, bucket, key,
52-
Callback=ProgressPercentage(progress),
53-
ExtraArgs=self._upload_args)
50+
with file_path.open('rb') as file:
51+
self._client.upload_fileobj(file, bucket, key,
52+
Callback=ProgressPercentage(progress),
53+
ExtraArgs=self._upload_args)
5454

5555
def download_file(self, local_path: Path, bucket: str, key: str):
5656
file_size = self.get_file_stats(bucket, key)['ContentLength']

cirro/file_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def upload_directory(directory: str, files: List[str], s3_client: S3Client, buck
110110
# Try the upload
111111
try:
112112
s3_client.upload_file(
113-
local_path=local_path,
113+
file_path=local_path,
114114
bucket=bucket,
115115
key=key
116116
)

0 commit comments

Comments
 (0)