【问题标题】:list azure blobs based on metadata - python sdk基于元数据列出 azure blob - python sdk
【发布时间】:2020-09-03 07:35:58
【问题描述】:

我正在使用 azure blob storage 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 并进行列表理解。 - 谢谢!

【问题讨论】:

标签: python azure azure-storage-account


【解决方案1】:

您的 include 必须是 BlobProperties 列表:

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

blob_iter = container_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-python 和 https://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-

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 2022-01-05
    • 2018-06-09
    • 2019-06-09
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多