如何从Azure Blob存储中的文件夹下载文件?

时间:2020-02-19 11:20:13

标签: c# azure azure-storage-blobs azure-sdk-.net

我想知道如何从azure blob内部创建的文件夹中下载文件。示意图如下所示:

MyContainer(容器)-> HomeFolder-> Sample.txt(Blob)

如果没有文件夹,并且只有sample.txt文件,那么我可以下载文件,但是当文件位于文件夹中时不能下载。

在stackeoverflow上,我看到大多数问题与直接在容器下的文件有关。有人可以指导我上述要求吗?

2)另一个问题是我想通过最新的azure sdk [Azure.Storage.Blobs]来执行此操作,但是如果有人使用[Microsoft.Azure.Storage.Blob] dll,就可以了。

下面是我目前正在使用[Microsoft.Azure.Storage.Blob]类编写的代码。

class Program
{
    static void Main(string[] args)
    {
        string storageAccount_connectionString = "DefaultEndpointsProtocol=https;AccountName=<account key>;EndpointSuffix=core.windows.net";
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageAccount_connectionString);

        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        CloudBlobContainer container = blobClient.GetContainerReference("lbdemocontainers");
        string blobPrefix = null;
        bool useFlatBlobListing = false;
        var listOfFileNames = new List<string>();
        var blobs = container.ListBlobs(blobPrefix, useFlatBlobListing, BlobListingDetails.None);
        //var folders = blobs.Where(b => b as CloudBlobDirectory != null).ToList();
        //foreach (var folder in blobs)
        //{
        //    var blob = (CloudBlockBlob)folder;
        //    blob.FetchAttributes();
        //    listOfFileNames.Add(blob.Name);
        //}
        //var downloads = blobs.Select(blob => blob.Uri.Segments.Last()).ToList();
        var blobNames = blobs.OfType<CloudBlockBlob>().Select(b => b.Name).ToList();
        Console.ReadLine();

    }
}

从上面的代码中,它仅为我提供文件夹名称HomeFolder/

预先感谢

0 个答案:

没有答案
相关问题