Azure Blob存储库是否已更改?

问题描述 投票:0回答:2

我一直在使用WindowsAzure.Storage 8. *库来处理容器以移动一些blob。最近,我想使用Microsoft站点上的示例中的以下代码获取blob列表。 (https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-how-to-use-blobs#set-up-your-development-environment)当我尝试使用'ListBlobs()'时,该方法不再通过库提供。我在控制台应用程序中使用它,而现在我试图在.net核心Web应用程序中使用它。是否有不同的方法来获取不同环境中的blob列表?我只是不确定为什么该方法在相同的命名空间/库/版本中不可用...?

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));

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

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("photos");

// Loop over items within the container and output the length and URI.
foreach (IListBlobItem item in container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
    CloudBlockBlob blob = (CloudBlockBlob)item;

    Console.WriteLine("Block blob of length {0}: {1}",    blob.Properties.Length, blob.Uri);

}
else if (item.GetType() == typeof(CloudPageBlob))
{
    CloudPageBlob pageBlob = (CloudPageBlob)item;

    Console.WriteLine("Page blob of length {0}: {1}", pageBlob.Properties.Length, pageBlob.Uri);

}
else if (item.GetType() == typeof(CloudBlobDirectory))
{
    CloudBlobDirectory directory = (CloudBlobDirectory)item;

    Console.WriteLine("Directory: {0}", directory.Uri);
}
}
azure azure-blob-storage
2个回答
1
投票

根据这个问题:qazxsw boi,Net Core / Net Standard支持还没有包括API的Sync实现。

由于ListBlobs是一种同步方法,因此在不支持同步方法的平台上缺失,因此您只调用ListBlobsSegmentedAsync并处理它返回的延续令牌。

有关如何使用ListBlobsSegmentedAsync列出blob的更多详细信息,您可以参考以下链接的示例:Missing syncronous methods for dotnet core?


0
投票

从9.4.2 SDK开始,Microsoft带回了同步实现:CloudBlobClient.ListBlobsSegmentedAsync Method

© www.soinside.com 2019 - 2024. All rights reserved.