0
votes

We have created a storage account for images and uploaded many images with the metadata property set. (as given below)

 public async Task<bool> UploadFileToBlob(CustomFile file)
    {
        // Get Blob Container
        CloudBlobContainer container = BlobUtilities.GetBlobClient.GetContainerReference("documents");
        container.CreateIfNotExists();

        // Get reference to blob (binary content)
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(file.FileName);

        // set its properties
        blockBlob.Properties.ContentType = file.FileMime;
        blockBlob.Metadata["tag"] = "computer";
        :
        :
}

There could be multiple images could have uploaded with the same tag name as a meta data property.

Now, I need to just get the list of images from the blob container which are mapped with the same tag name (I saw samples to download all the blobcontent but I want to specifically get the filtered list with the specific tag name which was set in the meta data of the uploaded file)

Thanks

2
I do believe there is now some Azure Search indexing service or some such which runs over blob metadata. Came across it the other day. Give it a search. - Sentinel

2 Answers

0
votes

It's not supported to filter metadata in a server query. You would need to list all the blobs with BlobListingDetails.Metadata, and filter the tag name on client side.

0
votes

There could be multiple images could have uploaded with the same tag name as a meta data property. Now, I need to just get the list of images from the blob container which are mapped with the same tag name.

As Zhaoxing Lu answered that there is no build-in features for you to achieve your purpose. Per my understanding, you could include path information in your blob names, you could create a virtual directory structure based on the tag category as follows:

https://{accountname}.blob.core.windows.net/{container-name}/{tag01}/photo1.jpg
https://{accountname}.blob.core.windows.net/{container-name}/{tag01}/photo2.jpg
https://{accountname}.blob.core.windows.net/{container-name}/{tag02}/photo3.jpg

Then, you could leverage ListBlobs and specify the prefix parameter as follows to retrieve your blobs:

var blockBlobs = container.ListBlobs(prefix: "tag01").OfType<CloudBlockBlob>();