如何解决按多个元数据项查询 Azure blob 存储的最佳方式
我正在编写一些代码,通过传入 X 个元数据键/值对来查询 azure blob 存储。
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);
}
这可能会很慢。
解决方法
您可以考虑使用 Azure Search 搜索 Blob 元数据,这样效率更高。
官方教程如下:
How to configure a blob indexer in Azure Cognitive Search
Search over Azure Blob storage content
您也可以通过创建 Azure Search 服务在门户网站上执行此操作: 你可以跟着这个video。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。