c# - Windows 通用应用程序 - 从 Azure 容器下载所有 Blob

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

我有一个通用 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 does not contain a definition of Uri.

Cannot declare variable of static type File.

Cannot create an instance of the static class file.

最佳答案

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

有关引用,请参阅here .

关于c# - Windows 通用应用程序 - 从 Azure 容器下载所有 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35232272/

相关文章:

c#故障转储不存在

c# - Python 中的 time.ctime(secs) 函数给出了与在 C# 中使用 DateTime 不同的日期

python - 在 Ubuntu/Ansible 上运行 playbook 时出现 ModuleNotFoundError

azure - 从现有 Azure 对象(例如 VM 或 VNET)创建 ARM 模板

azure - 使用 C# 从 Azure 存储中删除 Blob

amazon-web-services - 将大量数据上传到 Azure Blob 存储的最有效方法

azure - 防止 Azure 中的 Blob 出现 'Change Tier'

c# - 如何找到对程序集的依赖

c# - 使用 SQL Server 帐户(2005 和 2008)

azure - 当 CPU 使用率低于 10% 时停止 Azure 中的 VM