我正在使用下面的python代码从下载整个目录
from google.cloud import storage
from pathlib import Path
def download_blob():
"""Downloads a blob from the bucket."""
# The ID of your GCS bucket
bucket_name = "Bucket name"
# The ID of your GCS object
blob_name = input("Enter the folder name in "+bucket_name+" : ")
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blobs = bucket.list_blobs(prefix=blob_name) # Get list of files
print('Downloading file')
for blob in blobs:
if blob.name.endswith("/"):
continue
file_split = blob.name.split("/")
directory = "/".join(file_split[0:-1])
Path(directory).mkdir(parents=True, exist_ok=True)
blob.download_to_filename(blob.name)
print('Download completed')
download_blob()如何在打印“下载文件”行后显示进度条
发布于 2022-11-08 11:12:29
我将假设您有一个Python库,它能够在您计划运行此程序的控制台/终端上显示一个进度条。
您可以在粗略的级别上做以下工作:
size的属性。这可以告诉您每个小块的字节数。download_to_filename循环,在该循环中下载每个blob,然后每次下载完成后,在进度条中更新% complete。或者,如果您真的想要细粒度百分比,那么您可能需要使用start和end方法的参数,在这些参数中,您只能获得特定的字节数。请参考文档。
https://stackoverflow.com/questions/74358644
复制相似问题