gpt4 book ai didi

python - 基于元数据列出 azure blob - python sdk

转载 作者:行者123 更新时间:2023-12-02 07:22:08 26 4
gpt4 key购买 nike

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

最佳答案

您的包含内容必须是 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://learn.microsoft.com/de-de/python/api/azure-storage-blob/azure.storage.blob.blobproperties?view=azure-pythonhttps://learn.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-

关于python - 基于元数据列出 azure blob - python sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63718919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com