列出基于元数据的天蓝色斑点-python sdk

时间:2020-09-03 07:35:58

标签: python azure azure-storage-account

我正在使用azure blob存储sdk,希望能够有一种基于某些元数据信息过滤blob的方法。

from azure.storage.blob import BlobServiceClient

container_name = 'c1'
blob_service_client = BlobServiceClient.from_connection_string(os.environ['STORAGE_ACCOUNT_CONNECTION_STRING'])
container_client = blob_service_client.get_container_client(container_name)

all_blobs = container_client.list_blobs(include='metadata')

for in in all_blobs:
    print('{}'.format(i.name))

我在该帐户中保存了数千个Blob,我想在我的应用中更快地进行搜索-是否可以根据元数据进行过滤?我不想查询所有Blob并进行列表理解。 -谢谢!

1 个答案:

答案 0 :(得分:0)

您的包含必须是 BlobProperties 列表:

service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = service_client.get_container_client(container_name)

blob_iter = service_client.list_blobs(name_starts_with=None, include=["metadata"])
for i in blob_iter:
    print(i)

参考见:https://docs.microsoft.com/de-de/python/api/azure-storage-blob/azure.storage.blob.blobproperties?view=azure-pythonhttps://docs.microsoft.com/de-de/python/api/azure-storage-blob/azure.storage.blob.containerclient?view=azure-python#list-blobs-name-starts-with-none--include-none----kwargs-