我正在嘗試通過容器中的 blob 進行迭代,但我遇到了錯誤。我正在使用 Microsoft Docs 中的以下代碼:我遇到的主要錯誤之一是呼叫 ToListAsync() 方法時
// Iterate through the blobs in a container
List<BlobItem> segment = await blobContainer.GetBlobsAsync(prefix: "").ToListAsync();
foreach (BlobItem blobItem in segment)
{
BlobClient blob = blobContainer.GetBlobClient(blobItem.Name);
// Check the source file's metadata
Response<BlobProperties> propertiesResponse = await blob.GetPropertiesAsync();
BlobProperties properties = propertiesResponse.Value;
// Check the last modified date and time
// Add the blob to the list if has been modified since the specified date and time
if (DateTimeOffset.Compare(properties.LastModified.ToUniversalTime(), transferBlobsModifiedSince.ToUniversalTime()) > 0)
{
blobList.Add(blob);
}
}
這些是錯誤:


uj5u.com熱心網友回復:
來自https://docs.microsoft.com/en-us/dotnet/azure/sdk/pagination#use-systemlinqasync-with-asyncpageable
System.Linq.Async 包提供了一組對
IAsyncEnumerable<T>型別進行操作的LINQ 方法。由于AsyncPageable<T>implementsIAsyncEnumerable<T>,您可以使用它System.Linq.Async來查詢和轉換資料。
因此,請確保您的專案中包含 System.Linq.Async 包,以及using System.Linq.Async;C# 檔案中的指令。
請注意,使用IAsyncEnumerable<>: 如果您有很多 blob,最好通過集合流式傳輸,而不是將所有值加載到記憶體串列中。
IAsyncEnumerable<BlobItem> segment = blobContainer.GetBlobsAsync(prefix: "");
await foreach (BlobItem blobItem in segment)
{
...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/495255.html
上一篇:Py4JJavaError:呼叫o3858.save時出錯。:org.apache.spark.SparkException:寫作業中止
