Skip to content

Instantly share code, notes, and snippets.

@tyhoff
Last active September 23, 2024 08:13
Show Gist options
  • Save tyhoff/b757e6af83c1fd2b7b83057adf02c139 to your computer and use it in GitHub Desktop.
Save tyhoff/b757e6af83c1fd2b7b83057adf02c139 to your computer and use it in GitHub Desktop.
Python requests HTTP PUT with tqdm progress bar
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)
@Bumerang505
Copy link

Thank you very much!

@gauss-clb
Copy link

gauss-clb commented Jul 22, 2024

Good job!

@scottsavage
Copy link

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