【发布时间】:2021-01-12 16:24:20
【问题描述】:
我正在编写一些代码,通过传入 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);
}
这可能会很慢。
查询多个元数据键/值对的最佳方法是什么?
【问题讨论】:
-
我更新了一个带视频的链接,这样比较好理解,你可以看看。 @ttaylor27272727
标签: c# azure-blob-storage