【问题标题】:Query a Blob container to retrieve files查询 Blob 容器以检索文件
【发布时间】:2017-10-01 21:43:48
【问题描述】:

我在 Blob 容器中有一些 .png 文件,我可以通过将文件名作为参数传递来检索文件:

var blob = container.GetBlockBlobReference(System.IO.Path.GetFileName(fileName));

但我想查询该 Blob 容器并获得它包含的所有文件的列表。我该怎么做?

 public class FilesController : Controller
    {
        private CloudBlobContainer container;
        private CloudStorageAccount storageAccount;
        private CloudBlobClient blobClient;
        private CloudTableClient tableClient;
 public FilesController()
        {
            this.storageAccount = CloudStorageAccount.Parse(_dbConnection.ConnectionAzure);
            this.storageAccount.CreateCloudBlobClient();
            this.blobClient = storageAccount.CreateCloudBlobClient();
            this.container = blobClient.GetContainerReference("public/MyFolder");
            this.tableClient = storageAccount.CreateCloudTableClient();
        }

public ActionResult MyMethod(string fileName)
        {
           var blob = container.GetBlockBlobReference(System.IO.Path.GetFileName(fileName));
        }

【问题讨论】:

    标签: c# azure-blob-storage


    【解决方案1】:

    这个怎么样:

    var list = container.ListBlobs(useFlatBlobListing: true);
    var listOfFileNames = new List<string>();
    
    foreach (var blob in blobs) {
      var blobFileName = blob.Uri.Segments.Last();
      listOfFileNames.Add(blobFileName); 
    }
    
    return listOfFileNames;
    

    来源:Getting list of names of Azure blob files in a container?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-17
      • 2010-09-08
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 2018-04-13
      相关资源
      最近更新 更多