c# - Azure 中具有目录结构的 Blob 的 URL
问题描述
正在使用的程序集:程序集 Microsoft.WindowsAzure.Storage,版本=9.3.1.0
我想要做什么:在我的 Azure 存储中,我将图像存储为 blob,以下列方式
我想获取所有图像 blob 的 URL 以及它们最后修改的时间戳。
请注意Image1
和Image4
可能具有相同的名称。
我尝试过的:
ListBlobsSegmentedAsync(BlobContinuationToken currentToken)
我从容器的根目录尝试使用GetDirectoryReference(string relativeAddress)
,但无法获得所需的结果。虽然有点偏离轨道,但我可以通过
GetBlockBlobReference(string blobName);
我应该怎么办?
提前致谢。
解决方案
该ListBlobsSegmentedAsync
方法有 2 个包含useFlatBlobListing
参数的重载。这些重载接受 7 或 8 个参数,我在您的代码中计算了 6 个。
使用以下代码列出容器中的所有 blob。
public static async Task test()
{
StorageCredentials storageCredentials = new StorageCredentials("xxx", "xxxxx");
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("container");
BlobContinuationToken blobContinuationToken = null;
var resultSegment = await container.ListBlobsSegmentedAsync(
prefix: null,
useFlatBlobListing: true,
blobListingDetails: BlobListingDetails.None,
maxResults: null,
currentToken: blobContinuationToken,
options: null,
operationContext: null
);
// Get the value of the continuation token returned by the listing call.
blobContinuationToken = resultSegment.ContinuationToken;
foreach (IListBlobItem item in resultSegment.Results)
{
Console.WriteLine(item.Uri);
}
}
结果如下:
推荐阅读
- r - ggplot颜色,形状和大小按数据框中的因子变量在几个带有图例的区域
- javascript - 请问我怎样才能达到预期的结果
- javascript - Group Anagrams 算法性能
- javascript - Google Analytics dataLayer.push 在 Javascript Promise 中不起作用
- python - Python 上的 Selenium - 提交方法似乎无法正确发送请求?
- python - xmlschema 元素不是架构的元素
- javascript - 使用promise.all 使用rn-fetch-blob 下载图像?
- java - 如何验证休息控制器的参数
- php - 错误 file_get_contents(): 读取 8192 字节失败,errno=21
- javascript - 有人可以解释下面关于 JavaScript 的 concat() 和 slice() 方法的示例吗?