C# Azure中具有目录结构的Blob的URL

C# Azure中具有目录结构的Blob的URL,c#,azure,azure-storage-blobs,azure-blob-storage,C#,Azure,Azure Storage Blobs,Azure Blob Storage,正在使用的程序集:程序集Microsoft.WindowsAzure.Storage,版本=9.3.1.0 我想做什么: 在我的Azure存储中,我以以下方式将图像存储为blob 我想获得所有图像blob的URL以及它们最后修改的时间戳 请注意,Image1和Image4可能具有相同的名称 我所尝试的: 我尝试了从容器的根目录使用GetDirectoryReference(string relativeAddress)列出BlobsSegmentedAsync(BlobContinuation

正在使用的程序集:程序集Microsoft.WindowsAzure.Storage,版本=9.3.1.0

我想做什么: 在我的Azure存储中,我以以下方式将图像存储为blob

我想获得所有图像blob的URL以及它们最后修改的时间戳

请注意,
Image1
Image4
可能具有相同的名称

我所尝试的

  • 我尝试了从容器的根目录使用
    GetDirectoryReference(string relativeAddress)
    列出BlobsSegmentedAsync(BlobContinuationToken currentToken),但没有得到想要的结果

  • 虽然有点偏离正轨,但我能够通过
    GetBlockBlobReference(stringblobname)获得blob细节

  • 我该怎么办


    提前感谢。

    请使用以下参数尝试此覆盖:

    prefix: ""
    
    useFlatBlobListing: true
    
    blobListingDetails: BlobListingDetails.All
    
    maxResults: 5000
    
    currentToken: null or the continuation token returned
    

    这将返回所有blob(包括虚拟文件夹内部)的列表。

    ListBlobsSegmentedAsync
    方法有两个重载,其中包含
    useFlatBlobListing
    参数。这些重载接受7或8个参数,我在代码中计算6个参数

    使用以下代码列出容器中的所有blob

    public static async Task test()
    {
        StorageCredentials storageCredentials = new StorageCredentials("xxx", "xxxxx");
        CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference("container");
        BlobContinuationToken blobContinuationToken = null;
        var resultSegment = await container.ListBlobsSegmentedAsync(
             prefix: null,
             useFlatBlobListing: true,
             blobListingDetails: BlobListingDetails.None,
             maxResults: null,
             currentToken: blobContinuationToken,
             options: null,
             operationContext: null
         );
    
         // Get the value of the continuation token returned by the listing call.
         blobContinuationToken = resultSegment.ContinuationToken;
         foreach (IListBlobItem item in resultSegment.Results)
         {
              Console.WriteLine(item.Uri);
         }
    }
    
    结果如下:


    请记住,blob存储实际上没有文件夹,它们是虚拟的。因此,您确实有一些名为“Folder1/Image1.png”的blob。ListBlobsSegmented应该为您提供所有Blob,您可以显示您尝试过的代码吗?谢谢,我错误地使用了“CloudBlobClient”的“ListBlobsSegmentedAsync”。