Created
March 31, 2021 10:43
-
-
Save PatrykGala/78875d8626f171a3145dae677e7332fa to your computer and use it in GitHub Desktop.
GCS resumable api, upload status
This file contains hidden or 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
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