I'm using the azure blob storage sdk and I hoped that there would be way to filter blobs based on certain metadata information.
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))
I have several thousand blobs saved in that account and I want to make the search faster in my app - is there a way to filter based on metadata? I don't want to query all of the blobs and make a list comprehension. - thanks!
Your include needs to be a list of 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)
reference see: https://docs.microsoft.com/de-de/python/api/azure-storage-blob/azure.storage.blob.blobproperties?view=azure-python and 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-
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.