2017-03-09 39 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)等等。 –