【问题标题】:ListBlobs not available in cloudblobdirectory class?ListBlobs 在 cloudblobdirectory 类中不可用?
【发布时间】:2017-11-18 11:56:06
【问题描述】:

我已经在我的 .net core 2.0 项目中安装了最新的 windows azure nuget 包。安装版本:8.6.0.0

在 8.1.4 版本中,我使用以下语法使用 listblobs 方法获取项目列表。

CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path);
                IEnumerable<IListBlobItem> items = sampleDirectory.ListBlobs(false, BlobListingDetails.Metadata);

当尝试在 .net core 2.0 项目中使用与 8.6.0.0 windows azure 版本相同的代码块时,它会抛出错误

“cloudblob 目录不包含 listblob 的定义”。

如何获取此版本中的文件项?

同样,“CloudBlockBlob”中的 UploadText() 方法在此版本中也没有。

任何人请提出这个问题的解决方案?

【问题讨论】:

  • 如果我没记错的话,.Net 存储客户端库的核心实现只包括异步方法。没有可用的同步方法。
  • 是的@gauravMantri。是否有使用此异步方法获取文件的想法。我尝试使用以下代码 CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path); Task item = sampleDirectory.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, null, null, options, context);但结果返回为 null
  • 你不应该是awaiting异步操作吗?尝试以下代码行:Task&lt;BlobResultSegment&gt; item = await sampleDirectory.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, null, null, options, context);。 HTH。

标签: c# azure azure-storage azure-blob-storage


【解决方案1】:

请任何人提出这个问题的解决方案?

正如 Gaurav Mantri 提到的那样,Net core implementation of storage client library only includes async methods. There're no sync methods available。

请尝试使用以下演示代码。我也做了一个演示,它可以正常工作。

var blobs = sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.Metadata, 100, null, null, null).Result;

演示代码:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("Storage connection string");

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("Container name");

// Create the container if it doesn't already exist.
container.CreateIfNotExistsAsync();
CloudBlobDirectory sampleDirectory = container.GetDirectoryReference("directory name");

var blobs = sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.Metadata, 100, null, null, null).Result;

【讨论】:

    猜你喜欢
    • 2018-02-08
    • 2019-11-26
    • 1970-01-01
    • 2022-01-16
    • 2021-03-15
    • 2012-02-29
    • 1970-01-01
    • 2020-02-05
    • 2023-03-17
    相关资源
    最近更新 更多