2017-03-09 38 views
0

我一直在使用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应用程序中使用它。有不同的方法来获取不同环境下的斑点列表吗?我只是不确定为什么该方法不可用在相同的名称空间/库/版本...?Azure 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); 
} 
} 
+0

是否仍适用于您的控制台应用程序? (而不是.net核心版本)? –

+0

@ThiagoCustodio是的。 – JReam

+0

我认为这是与.net核心版本有关的错误。我建议你直接在Github上打开一个问题。 https://github.com/Azure/azure-storage-net –

回答

1

根据这个问题:Missing syncronous methods for dotnet core?,磊科/ Netstandard支持还不包括同步实施的API。

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

更多有关如何使用ListBlobsSegmentedAsync列出的blob的详细信息,您可以参考以下网站的例子: CloudBlobClient.ListBlobsSegmentedAsync Method

+0

谢谢。我接受你的答案,因为异步方法的作品。但是我在.net内核中使用了非异步方法,所以我不确定这个'因此在不支持同步方法的平台上是否丢失'对我来说完全有意义。 – JReam

+0

我同意你的观点,我的意思是.net核心现在不支持API的Sync实现,所以我们不能使用ListBlobs方法或table.execute(tablequery)等等。 –