C# 找不到返回的有效Azure存储URI

C# 找不到返回的有效Azure存储URI,c#,azure,azure-storage-blobs,C#,Azure,Azure Storage Blobs,我正在尝试从Azure存储帐户中的虚拟目录检索所有映像文件。文件夹路径(容器URI)正确,但正在返回 StorageException:请求的URI不表示服务器上的任何资源 在浏览器中粘贴URI会产生 BlobNotFound 指定的blob不存在。请求ID:622f4500-a01e-0022-7dd0-7d9428000000时间:2019-10-08T12:02:29.6389180Z URI是公共的,工作正常;您可以通过在浏览器中粘贴URI或单击下面的引擎视频链接来查看此视频 我的

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

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

在浏览器中粘贴URI会产生

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

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

我的代码获取容器,其URI为

公共异步任务GetBlobFileListAsync(CloudBlobContainer blobContainer,字符串客户)
{
var files=新列表();
BlobContinuationToken BlobContinuationToken=null;
做
{
//代码在下面的行中失败
var segments=等待blobContainer.ListBlobSegmentedAsync(null,blobContinuationToken);
blobContinuationToken=segments.ContinuationToken;
files.AddRange(segments.Results.Select(x=>GetFileNameFromBlobUri(x.Uri,customer));
}while(blobContinuationToken!=null);
归还文件;
}
var segments=await blobContainer…上的代码失败…。代码行 并且并不是容器导致了错误(IMO),因为您可以看到容器返回了一个有效的URI

并且虚拟文件夹包含文件


我很想知道我做错了什么。

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中包含了一些虚拟文件夹路径,这可能是在搞乱什么

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

下面的代码运行良好

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;
    }
公共异步任务GetImagesFromVirtualFolder(CloudBlobContainer blobContainer,string客户)
{
var images=新列表();
BlobContinuationToken BlobContinuationToken=null;
做
{
//这是要使用的重载,如果传入从主容器到文件所在位置的完整虚拟路径(前缀),请使用
//使用FlatBloblisting(第2个参数中的真值)、BlobListingDetail,我选择100作为最大Blob数(参数4)
//然后,令牌和最后两个参数可以为null
var results=等待blobContainer。
ListBlobsSegmentedAsync(“publicfiles/images/”+customer,true,BlobListingDetails.All,100,blobContinuationToken,null,null);
//获取清单调用返回的延续令牌的值。
blobContinuationToken=results.ContinuationToken;
foreach(results.results中的var项)
{
var filename=GetFileNameFromBlobUri(item.Uri,customer);
var img=新的评估图像
{
ImageUrl=item.Uri.ToString(),
ImageCaption=GetCaptionFromFilename(文件名),
IsPosterImage=filename.Contains(“海报”)
};
图像。添加(img);
}
}while(blobContinuationToken!=null);
返回图像;
}

@Gaurav Mantri…你是这里的专家,对这篇文章有什么想法吗?@juunas…是的,/publicfiles/images/robson是一个虚拟文件夹路径。你是说我经过的那个集装箱只是主集装箱吗?如果是这样,我如何只迭代我想要的虚拟文件路径而不是容器中的所有blob?将容器URI放在文章中,以enerteck结尾,也会产生一个resource not found错误。我认为您可能能够进行前缀筛选,比如获取所有以虚拟文件夹路径开头的文件。但是你仍然不能列出文件的事实有点奇怪。你能在你的问题中添加一些代码来说明如何初始化路径等吗?@juunas…你是对的,当使用主容器时,代码不会失败,但它只返回两个blob,即主容器下的两个子文件夹privatefiles和publicfiles。必须有一种方法来迭代虚拟文件夹中的文件path@juunas...so你使用主容器的想法是对的。我和其他重载混在一起,这就是如何去做。如果您在答案中添加7个参数的第一个重载,我会将您的答案标记为答案。您需要前缀、bloblingDetails和FlatBlobListing值才能在虚拟文件夹路径中获取文件。
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;
    }