Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

c# - Best way to query Azure blob storage by multiple metadata items

I'm working on some code to query azure blob storage by passing in a X number of metadata key/value pairs.

I have this code right now to search for one:

            BlobContainerClient container = GetBlobContainerForDownloads(blobContainerClient);

            var blobItems = GetAllBlobsForContainer(container);

            if (blobItems == null)
            {
                return Enumerable.Empty<AzureStorageFileDownloadResultDTO>();
            }

            IList<AzureStorageFileDownloadResultDTO> results = new List<AzureStorageFileDownloadResultDTO>();

            AzureStorageFileDownloadResultDTO result;

            foreach (var item in blobItems.Where(w => w.Metadata.Contains(new KeyValuePair<string, string>(FileManagerMetadataContants.ModuleType, moduleType.ToString())) == true && w.Metadata.Contains(new KeyValuePair<string, string>(metaDataKey, metaDataValue)) == true && w.Metadata.Contains(new KeyValuePair<string, string>(FileManagerMetadataContants.IsFileDeleted, FileManagerMetadataContants.IsFileDeletedValue)) == false))
            {
                result = new AzureStorageFileDownloadResultDTO()
                {
                    FileData = null, // do not pull the file data when returning all the files ; the developer will return back to the API to get the actual file with the blob name
                    FileFound = true,
                    BlobName = item.Name,
                    FileName = GetFileName(item.Metadata),
                    FileNameWithExtension = GetFileNameWithExtension(item.Metadata),
                    ContentType = item.Properties.ContentType,
                    FileExtension = item.Properties.ContentType,
                    MetaData = item.Metadata
                };

                results.Add(result);
            }

This could be slow in time.

What is the best way to query multiple metadata key/value pairs?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could consider searching Blob meta data using Azure Search, which is more efficient.

Here is the official tutorial:

How to configure a blob indexer in Azure Cognitive Search

Search over Azure Blob storage content

You could also do it on portal through create Azure Search service: enter image description here You could follow with this video.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...