繁体   English   中英

使用 python azure sdk 查找 blob 大小

[英]using python azure sdk find blob size

我正在尝试使用 azure python sdk BlobServiceClient 找出 blob 大小。 下面的代码我使用了之前版本的azure.storage.blob python package。在新的BlobServiceClient class 中是否有类似于get_blob_properties的属性。

import os
from azure.storage.blob import BlockBlobService, PublicAccess

CONTAINER_NAME = os.environ["AZURE_CONTAINER_NAME"]
AZURE_STORAGE_ACCOUNT = os.environ["AZURE_STORAGE_ACCOUNT"]
AZURE_STORAGE_KEY = os.environ["AZURE_STORAGE_KEY"]

bbs = BlockBlobService(
    account_name=AZURE_STORAGE_ACCOUNT,
    account_key=AZURE_STORAGE_KEY)

bbs = BlockBlobService(
    account_name=AZURE_STORAGE_ACCOUNT,
    account_key=AZURE_STORAGE_KEY)

total_size = 0
generator = bbs.list_blobs(CONTAINER_NAME)

for blob in generator:
    curr_blob = BlockBlobService.get_blob_properties(
                bbs,
                CONTAINER_NAME,
                blob.name)
    length = curr_blob.properties.content_length
    total_size = total_size + length

这是你想要的? 我从另一个类似的 SO 问题中得到了这个。 关联

from azure.storage.blob import BlobServiceClient
my_container = "test"
connect_str = "DefaultEndpoinxxxxxxxxxxxxxxxxxxx"
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
blob_list = blob_service_client.get_container_client(my_container).list_blobs()
for blob in blob_list:
    print("\t" + blob.name)
    print('\tsize=', blob.size)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM