【问题标题】:Windows Universal App - Download all Blobs from Azure ContainerWindows 通用应用程序 - 从 Azure 容器下载所有 Blob
【发布时间】:2016-02-06 04:59:21
【问题描述】:

我有一个通用 Windows 应用程序。

我正在尝试在应用启动时从 azure 容器下载所有 blob。这是我的代码:

 public MainPage()
    {
        this.InitializeComponent();
        downloadblobs();
    }

public async void downloadblobs()
{
    CloudStorageAccount storageaccount = new CloudStorageAccount(new StorageCredentials("accountname", "accountkey"), true);
    CloudBlobClient blobClient = storageaccount.CreateCloudBlobClient();
    CloudBlobContainer container = blobClient.GetContainerReference("ContainerName");

    //---------------------
    int fileName = 1;
    var client = storageaccount.CreateCloudBlobClient();
    BlobContinuationToken continuationToken = null;
    string prefix = null;
    bool useFlatBlobListing = true;
    BlobListingDetails blobListingDetails = BlobListingDetails.All;
    int maxBlobsPerRequest = 2500;
    List<IListBlobItem> blobs = new List<IListBlobItem>();
    do
    {
        var listingResult = await container.ListBlobsSegmentedAsync(prefix, useFlatBlobListing, blobListingDetails, maxBlobsPerRequest, continuationToken, null, null);
        continuationToken = listingResult.ContinuationToken;
        blobs.AddRange(listingResult.Results);
        using (var fileStream = System.IO.File.OpenWrite(@"\NewImages\" + fileName + ".jpg"))
        {
            var blobReference = blobClient.GetBlobReferenceFromServerAsync(blobs.Uri);
            File downloadedFile = new File(blobReference + ".jpg");
            fileName++;
        }
    }
    while (continuationToken != null);
}

我在两行出现错误:

            var blobReference = blobClient.GetBlobReferenceFromServerAsync(blobs.Uri);
            File downloadedFile = new File(blobReference + ".jpg");

我的错误是:

ListBlobItem 不包含 Uri 的定义。

不能声明静态类型文件的变量。

无法创建静态类文件的实例。

【问题讨论】:

    标签: c# azure azure-storage win-universal-app


    【解决方案1】:

    您需要使用container.listBlobsSegmentedAsync() 枚举容器中的blob。容器引用不仅仅有一个自动下载的 blob 列表。

    有关参考,请参阅here

    【讨论】:

    • 我尝试使用此链接:ahmetalpbalkan.com/blog/… 和此链接stackoverflow.com/questions/16052813/…,但无法使其正常工作。我完全迷路了!
    • 您应该编辑您的问题以显示您对listBlobsSegmentedAsync() 所做的尝试。这样可能有人可以提供帮助。但底线:您当前的实现将无法正常工作,因为您从不检索 blob 列表。
    • 您有发送blob 以赢得通用设备的教程的链接吗?所有的 tut 在线只是告诉你如何将它们上传到天蓝色(我想这是 blob 行进的明显方向,但我正在搞乱房子的其他东西并想下载它们)
    • 教程推荐问题是题外话。您已经找到了准确描述如何从容器中检索 blob 列表的网页。还有其他讨论枚举的 stackoverflow 问题(同样,您已经找到了一篇这样的帖子)。 cmets这里就不讨论了。
    • 我已按照您的建议编辑了问题。谢谢。感谢您将我指向枚举的方向,以便我可以尝试使其正常工作。抱歉跑题了。不幸的是,枚举容器似乎并没有达到目的。如果您有更多的指导,也将不胜感激。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2016-09-01
    • 2020-10-13
    • 1970-01-01
    • 2014-09-20
    • 2018-04-13
    • 2023-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多