2017-11-18 192 views
0

我在我的.net core 2.0項目中安裝了最新的windows azure nuget軟件包。已安裝的版本:8.6.0.0ListBlobs在cloudblobdirectory類中不可用?

在8.1.4版本中,我使用下面的語法獲得使用listblobs方法的項目列表。

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

時嘗試使用相同的代碼塊在.NET 2.0的核心項目,8.6.0.0的Windows Azure版本,它會引發錯誤的

「cloudblobdirectory不包含listblobs的定義」。

如何獲取此版本中的文件項目?

同樣,「CloudBlockBlob」中的UploadText()方法在此版本中也不可用。

任何人都請爲這個問題提出解決方案?

+0

如果我沒有記錯,淨核心實現存儲客戶端庫僅包括異步方法。沒有可用的同步方法。 –

+0

是@gauravMantri。是否有使用這種異步方法獲取文件的想法。我試着在下面的代碼 CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path); 任務 item = sampleDirectory.ListBlobsSegmentedAsync(true,BlobListingDetails.Metadata,null,null,options,context); 但結果返回爲空 – Joy

+0

不應該等待異步操作嗎?嘗試下面這行代碼:'Task item = await sampleDirectory.ListBlobsSegmentedAsync(true,BlobListingDetails.Metadata,null,null,options,context);'。 HTH。 –

回答

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; 

enter image description here

相關問題