Skip to content

Instantly share code, notes, and snippets.

@PatrykGala
Created March 31, 2021 10:43
Show Gist options
  • Save PatrykGala/78875d8626f171a3145dae677e7332fa to your computer and use it in GitHub Desktop.
Save PatrykGala/78875d8626f171a3145dae677e7332fa to your computer and use it in GitHub Desktop.
GCS resumable api, upload status
import requests
from datetime import datetime
import time
file_size = 2194418361937 #TODO size in bytes
LOCATION = "https://storage.googleapis.com/upload/storage/v1/b/sc-9369-dataengineering-prod-qeppo-arch/o?uploadType=resumable&name=****" #TODO change location upload
while True:
res = requests.put(
url=LOCATION,
headers={
'Content-Length': '0',
"Content-Range": "bytes */file_size",
})
res.raise_for_status()
range = res.headers['range']
bytes = int(range.replace('bytes=0-', ''))
percentage = bytes / file_size * 100
print((datetime.now().strftime("%d-%m-%y %H:%M ") + ("%.1f" % percentage) + "%") + " " + (
"%.2f" % ((file_size - bytes) / 1024 / 1024 / 1024)) + "GB")
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment