Last active
September 23, 2024 08:13
-
-
Save tyhoff/b757e6af83c1fd2b7b83057adf02c139 to your computer and use it in GitHub Desktop.
Python requests HTTP PUT with tqdm progress bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tqdm import tqdm | |
from tqdm.utils import CallbackIOWrapper | |
file_path = os.path.abspath(__file__) | |
upload_url = https://some-bucket.s3.amazonaws.com | |
file_size = os.stat(file_path).st_size | |
with open(file_path, "rb") as f: | |
with tqdm(total=file_size, unit="B", unit_scale=True, unit_divisor=1024) as t: | |
wrapped_file = CallbackIOWrapper(t.update, f, "read") | |
requests.put(upload_url, data=wrapped_file) |
Thank you very much!
Good job!
This is the answer to not being able to stream binary files using requests. Thanks!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! This was very helpful to me