Skip to content

Commit 76dd303

Browse files
committed
feat(s3): upload/download progress indicators
1 parent 23f1107 commit 76dd303

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

utils/storage/S3Storage.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import os
44
import time
5+
from tqdm import tqdm
56
from botocore.client import Config
67

78

@@ -71,7 +72,13 @@ def upload_file(self, source, dest):
7172
dest = self.path
7273

7374
upload_start = get_now()
74-
result = self.bucket().upload_file(source, dest)
75+
file_size = os.stat(source)
76+
with tqdm(total=file_size, unit="B", unit_scale=True, desc="Uploading") as bar:
77+
result = self.bucket().upload_file(
78+
Filename=source,
79+
Key=dest,
80+
Callback=lambda bytes_transferred: bar.update(bytes_transferred),
81+
)
7582
print(result)
7683
upload_total = get_now() - upload_start
7784

@@ -81,4 +88,13 @@ def download_file(self, dest):
8188
if not dest:
8289
dest = self.path.split("/").pop()
8390
print(f"Downloading {self.url} to {dest}...")
84-
self.bucket().download_file(self.path, dest)
91+
object = self.s3().Object(self.bucket_name, self.path)
92+
object.load()
93+
94+
with tqdm(
95+
total=object.content_length, unit="B", unit_scale=True, desc="Downloading"
96+
) as bar:
97+
object.download_file(
98+
Filename=dest,
99+
Callback=lambda bytes_transffered: bar.update(bytes_transffered),
100+
)

0 commit comments

Comments
 (0)