简体   繁体   English

遍历 Azure SDK v12 中的 blob

[英]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.

相关问题 如何替换 Azure.Storage.Blobs v12 SDK 中的 CloudBlockBlob.OpenWriteAsync()? - How can I replace CloudBlockBlob.OpenWriteAsync() in the Azure.Storage.Blobs v12 SDK? Azure 存储 - 使用 v12 SDK for .NET 获取容器中的 blob 列表 - Azure Storage - Get a list of blobs in a container with the v12 SDK for .NET 使用适用于 .Net 的 Azure Bob Storage v12 SDK 进行加密 - Encryption with Azure Bob Storage v12 SDK for .Net 如何使用 Azure.Storage v12 中的 Azure KeyVault 密钥解密 blob - How do you decrypt blobs with Azure KeyVault keys in Azure.Storage v12 如何使用 Azure.Storage v12 SDK 从 Azure Blob 中删除元数据? - How can I remove metadata from an Azure Blob using Azure.Storage v12 SDK? 如何使用 .NET v12 SDK 在 Azure Blob 存储中使用指定的 ContentType 上传 Blob? - How upload blob in Azure Blob Storage with specified ContentType with .NET v12 SDK? v12 .NET SDK 中的 Azure Storage BlobClient 和 BlockBlobClient 有什么区别? - What is the difference between the Azure Storage BlobClient and BlockBlobClient in v12 .NET SDK? 如何使用最新的 Azure SDK .NET API v12 在 Blob 上获取共享访问签名? - How to get a Shared Access Signature on a Blob using the latest Azure SDK .NET API v12? 使用指定的 ContentType 将 blob 上传到 Azure Blob 存储并同时覆盖(.NET v12 SDK)? - Upload blob into Azure Blob Storage with specified ContentType and overwrite same time (.NET v12 SDK)? Azure Blob 存储使用 Key Vault.Net v12 解密 SDK - Azure Blob Storage Decrypt Using Key Vault .Net v12 SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM