【问题标题】:Best way to query Azure blob storage by multiple metadata items通过多个元数据项查询 Azure Blob 存储的最佳方式
【发布时间】: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


【解决方案1】:

您可以考虑使用更高效的 Azure Search 搜索 Blob 元数据。

这里是官方教程:

How to configure a blob indexer in Azure Cognitive Search

Search over Azure Blob storage content

您也可以通过创建 Azure 搜索 服务在门户上执行此操作: 你可以关注这个video

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2021-06-27
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多