【问题标题】:Valid Azure Storage URI returning not found未找到返回的有效 Azure 存储 URI
【发布时间】:2020-02-05 17:44:30
【问题描述】:

我正在尝试从我的 Azure 存储帐户中的虚拟目录中检索所有图像文件。文件夹的路径(容器 URI)正确但正在返回

StorageException:请求的 URI 不代表服务器上的任何资源。

在浏览器中粘贴 URI 生成

BlobNotFound 指定的 blob 不存在。 RequestId:622f4500-a01e-0022-7dd0-7d9428000000 时间:2019-10-08T12:02:29.6389180Z

公开的 URI 可以正常工作;您可以通过在浏览器中粘贴 URI 或单击下面的引擎视频链接来观看此视频。

Engine Video

我的代码抓取了容器,它的 URI 是https://batlgroupimages.blob.core.windows.net/enerteck/publicfiles/images/robson

public async Task<List<string>> GetBlobFileListAsync(CloudBlobContainer blobContainer, string customer)
{
    var files = new List<string>();
    BlobContinuationToken blobContinuationToken = null;
    do
    {
        //code fails on the line below
        var segments = await blobContainer.ListBlobsSegmentedAsync(null, blobContinuationToken);           
        blobContinuationToken = segments.ContinuationToken;
        files.AddRange(segments.Results.Select(x => GetFileNameFromBlobUri(x.Uri, customer)));
    } while (blobContinuationToken != null);
    return files;
}

代码在 var 段上失败 = await blobContainer…。代码行 并且它不是导致错误的容器(IMO),因为您可以看到容器返回一个有效的 URI

虚拟文件夹包含文件

我很想知道我在这里做错了什么。

【问题讨论】:

  • @Gaurav Mantri...你是这里的专家,对这篇文章有什么想法吗?

标签: c# azure azure-blob-storage


【解决方案1】:

https://batlgroupimages.blob.core.windows.net/enerteck/publicfiles/images/robson 不是容器 URI。

https://batlgroupimages.blob.core.windows.net/enerteck 是一个容器 URI。 publicfiles/images/robson/image.png 可能是该容器中的 blob 名称。

我在想你可能在容器 URI 中包含了一些虚拟文件夹路径,这可能会搞砸什么?

【讨论】:

  • @juunas...是的,/publicfiles/images/robson 是一个虚拟文件夹路径。所以你是说我传入的容器只是主容器吗?如果是这样,我如何只迭代我想要的虚拟文件路径而不是容器中的所有 blob?并将您在帖子中的容器 URI 以 enerteck 结尾,也会产生资源未找到错误。
  • 我想你也许可以做一个前缀过滤器,比如获取所有以虚拟文件夹路径开头的文件。但是您仍然无法列出文件的事实有点奇怪。您能否在您的问题中添加更多代码来展示您如何初始化路径等?
  • @juunas...你是对的,当使用主容器时,代码没有失败,但它只返回两个blob,主容器下的两个子文件夹,privatefiles和publicfiles。必须有一种方法可以遍历虚拟文件夹路径中的文件
  • @juunas ...所以您使用主容器是对的。我愚弄了其他重载,这是怎么回事。如果您添加到您的答案以使用具有 7 个参数的第一个重载,我会将您的答案标记为答案。您需要前缀、BlobListingDetails 和 FlatBlobListing 值来获取虚拟文件夹路径中的文件。
【解决方案2】:

所以答案在于我试图在虚拟文件夹路径中列出 blob 因此,在 OP 中,我试图使用包含 blob 的文件夹的完整路径列出 blob。你不能那样做。您必须在 MAIN CONTAINER 上使用 ListBlobsSegmentedAsync 的重载之一。感谢 juunas 让我意识到我不是从主容器开始的。我意识到他们必须是其他重载方法来完成我想要做的事情

下面的代码运行良好

public async Task<List<EvaluationImage>> GetImagesFromVirtualFolder(CloudBlobContainer blobContainer, string customer)
    {
        var images = new List<EvaluationImage>();
        BlobContinuationToken blobContinuationToken = null;
        do
        {
           //this is the overload to use, you pass in the full virtual path from the main container to where the files are (prefix), use a
          //useflatbloblisting (true value in 2nd parameter), BlobListingDetail, I chose 100 as the max number of blobs (parameter 4) 
          //then the token and the last two parameters can be null       
            var results = await blobContainer.
                ListBlobsSegmentedAsync("publicfiles/images/" + customer,true,BlobListingDetails.All, 100, blobContinuationToken,null,null);
            // Get the value of the continuation token returned by the listing call.
            blobContinuationToken = results.ContinuationToken;

            foreach (var item in results.Results)
            {
                var filename = GetFileNameFromBlobUri(item.Uri, customer);
                var img = new EvaluationImage
                {
                    ImageUrl = item.Uri.ToString(),
                    ImageCaption = GetCaptionFromFilename(filename),
                    IsPosterImage = filename.Contains("poster")
                };

                images.Add(img);
            }
        } while (blobContinuationToken != null);

        return images;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-28
    • 2013-01-01
    • 2013-04-02
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多