通用的Windows应用程序 - 下载来​​自Azure的集装箱全部斑点 [英] Windows Universal App - Download all Blobs from Azure Container

查看:148
本文介绍了通用的Windows应用程序 - 下载来​​自Azure的集装箱全部斑点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个万能的Windows应用程序。

我想从一个蓝色的容器下载所有斑点的应用程序启动时。这是我的code:

 公开的MainPage()
    {
        this.InitializeComponent();
        downloadblobs();
    }公共异步无效downloadblobs()
{
    CloudStorageAccount storageaccount =新CloudStorageAccount(新StorageCredentials(ACCOUNTNAME,accountkey),TRUE);
    CloudBlobClient blobClient = storageaccount.CreateCloudBlobClient();
    CloudBlobContainer容器= blobClient.GetContainerReference(容器名称);    // ---------------------
    INT文件名= 1;
    变种客户= storageaccount.CreateCloudBlobClient();
    BlobContinuationToken continuationToken = NULL;
    字符串preFIX = NULL;
    布尔useFlatBlobListing = TRUE;
    BlobListingDetails blobListingDetails = BlobListingDetails.All;
    INT maxBlobsPerRequest = 2500;
    清单< IListBlobItem>斑点=新的List< IListBlobItem>();
    做
    {
        VAR listingResult =等待container.ListBlobsSegmentedAsync(preFIX,useFlatBlobListing,blobListingDetails,maxBlobsPerRequest,continuationToken,NULL,NULL);
        continuationToken = listingResult.ContinuationToken;
        blobs.AddRange(listingResult.Results);
        使用(VAR FILESTREAM = System.IO.File.OpenWrite(@\\ NewImages \\+文件名+.JPG))
        {
            VAR blobReference = blobClient.GetBlobReferenceFromServerAsync(blobs.Uri);
            文件downloadedFile =新的文件(blobReference +.JPG);
            文件名++;
        }
    }
    而(continuationToken!= NULL);
}

即时得到错误的两行:

  VAR blobReference = blobClient.GetBlobReferenceFromServerAsync(blobs.Uri);
            文件downloadedFile =新的文件(blobReference +.JPG);

我的错误是:


  

ListBlobItem不包含的Uri的定义。


  
  

无法声明静态类型文件的变量。



  

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



解决方案

您需要枚举斑点在容器中,用 container.listBlobsSegmentedAsync()。容器参考并不仅仅具有与它自动下载斑点的列表。

有关参考,请参阅这里

I have a Universal Windows app.

I am trying to download all blobs from an azure container when the app starts. This is my code:

 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);
}

Im getting errors on two lines:

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

My errors are:

ListBlobItem does not contain a definition of Uri.

Cannot declare variable of static type File.

and

Cannot create an instance of the static class file.

解决方案

You need to enumerate the blobs in the container, with container.listBlobsSegmentedAsync(). The container reference doesn't just have a list of blobs automatically downloaded with it.

For reference, see here.

这篇关于通用的Windows应用程序 - 下载来​​自Azure的集装箱全部斑点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆