[英]Iterating through blobs in Azure SDK v12
I am upgrading a web app to use Azure SDK v 12.10我正在升级 Web 应用以使用 Azure SDK v 12.10
Before this, I was grabbing all the blobs in a virtual path from the container into a list and iterating through them.在此之前,我将容器中虚拟路径中的所有 blob 抓取到一个列表中并遍历它们。
var results = await blobContainer.
ListBlobsSegmentedAsync("publicfiles/images/" + customer.AzureFolderName, true, BlobListingDetails.All, 100, blobContinuationToken, null, null);
// Get the value of the continuation token returned by the listing call.
blobContinuationToken = results.ContinuationToken;
foreach (var item in results.Results)
{
var filename = GetFileNameFromBlobUri(item.Uri, customer.AzureFolderName);
var img = new EvaluationImage
{
ImageUrl = item.Uri.ToString(),
ImageCaption = GetCaptionFromFilename(filename),
IsPosterImage = filename.Contains("poster"),
ImagesForCompany = customer.CompanyName
};
images.Add(img);
}
All I can find from googling how to do so in the new SDK, yields this我可以从谷歌搜索如何在新的 SDK 中找到,产生这个
await foreach (BlobItem blob in blobContainer.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"publicfiles/images/{customer.AzureFolderName}"))
The problem is the "blob" variable (BlobItem) has minimal useable properties, for example, I need the Uri which was available before.问题是“blob”变量 (BlobItem) 具有最少的可用属性,例如,我需要之前可用的 Uri。 The "blob" variable in prior versions had a multitude of useable properties.先前版本中的“blob”变量有许多可用的属性。 Is there some other type (not BlobItem) that has these properties that I'm not finding in my searching?是否有其他类型(不是 BlobItem)具有我在搜索中找不到的这些属性?
I don't see anything useable in BlobTraits or BlobStates either that change this.我在 BlobTraits 或 BlobStates 中看不到任何可用的东西来改变这一点。
It's not as straight forward to get the URI of the blob in SDK version 12.x.在 SDK 版本 12.x 中获取 blob 的 URI 并不那么简单。 When you get a BlobItem
as part of listing result, you will need to create a BlobClient
object out of it and then you will be able to get the URI of the blob.当您获得BlobItem
作为列表结果的一部分时,您需要从中创建一个BlobClient
对象,然后您将能够获得 Blob 的 URI。
Here's the sample code to do so:这是执行此操作的示例代码:
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(container);
var listingResult = containerClient.GetBlobsAsync();
await foreach (var blobItem in listingResult)
{
BlobClient blobClient = containerClient.GetBlobClient(blobItem.Name);
Uri blobUri = blobClient.Uri;
//Do something with the URI...
}
Code above makes use ofAzure.Storage.Blobs (12.9.1)
SDK.上面的代码使用Azure.Storage.Blobs (12.9.1)
SDK。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.