【发布时间】:2017-07-29 18:51:47
【问题描述】:
我一直在使用 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);
}
}
【问题讨论】:
-
它仍然适用于您的控制台应用程序吗? (不是 .net 核心版本)?
-
@ThiagoCustodio 是的。
-
我认为这是一个与 .net 核心版本相关的错误。我建议你直接在 Github 上打开一个问题。 github.com/Azure/azure-storage-net
-
也许我错了,但github页面并没有说它支持.NET核心。
-
如果你要迁移到 Azure.Storage 命名空间,这个页面是我发现的最有用的东西 craftedforeveryone.com/…