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?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…