C# 通过多个元数据项查询Azure blob存储的最佳方法
我正在编写一些代码,通过传入X个元数据键/值对来查询azure blob存储 我现在有这个代码来搜索一个:C# 通过多个元数据项查询Azure blob存储的最佳方法,c#,azure-storage-blobs,C#,Azure Storage Blobs,我正在编写一些代码,通过传入X个元数据键/值对来查询azure blob存储 我现在有这个代码来搜索一个: BlobContainerClient container = GetBlobContainerForDownloads(blobContainerClient); var blobItems = GetAllBlobsForContainer(container); if (blobItems == null)
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);
}
BlobContainerClient容器=GetBlobContainerForDownloads(BlobContainerClient);
var blobItems=GetAllBlobsForContainer(容器);
if(blobItems==null)
{
返回可枚举的.Empty();
}
IList results=新列表();
AzureStorageFileDownloadResultToResult;
foreach(blobItems.Where(w=>w.Metadata.Contains)(新KeyValuePair(FileManagerMetadataContants.ModuleType,ModuleType.ToString())==true&&w.Metadata.Contains(新KeyValuePair(metaDataKey,metaDataValue))==true&&w.Metadata.Contains(新KeyValuePair(FileManagerMetadataContants.IsFileDeleted,FileManagerMetadataContants.IsFileDeletedValue))==false)
{
结果=新建AzureStorageFileDownloadResultTo()
{
FileData=null,//返回所有文件时不要拉取文件数据;开发人员将返回API以获取具有blob名称的实际文件
FileFound=true,
BlobName=item.Name,
FileName=GetFileName(item.Metadata),
FileNameWithExtension=GetFileNameWithExtension(item.Metadata),
ContentType=item.Properties.ContentType,
FileExtension=item.Properties.ContentType,
元数据=项。元数据
};
结果。添加(结果);
}
这可能是缓慢的时间
查询多个元数据键/值对的最佳方式是什么?
< P>可以考虑使用Azure搜索搜索BLUB元数据,这是更有效的。 以下是官方教程: 您还可以在门户网站上通过创建Azure搜索服务完成此操作:您可以这样做。我用视频更新了一个链接,这样更容易理解,您可以查看。@ttaylor2727