Home > Enterprise >  using python azure sdk find blob size
using python azure sdk find blob size

Time:12-09

I'm trying to find out blob size using azure python sdk BlobServiceClient. The below code I have uses the prior version of azure.storage.blob python package. Is there an attribute similar to get_blob_properties in the new BlobServiceClient class.

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

CodePudding user response:

Is this what you are looking for ? I got this from another similar SO question. LINK

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)
  • Related