【发布时间】:2014-11-07 04:53:29
【问题描述】:
我在 azure 存储上有一堆 blob,其名称遵循以下模式:<someName>_DateTimeOffset.UtcNow。当我使用 container.ListBlobs() 获取 blob 时,blob Uri 看起来像这样:<someName>__11%252f3%252f2014+10%253a00%253a00+PM+%252b00%253a00+%252b00%253a00。
如果仔细观察,%25 在编码一次后变为%,%2f 变为:。所以看起来 Uri 经历了双重编码。
当我试图抓住这个 blob 时,它不起作用。这是代码sn-p:
BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync("myPrefix", true, BlobListingDetails.All, 10, null, null, null);
var list = resultSegment.Results.Select(x => x.Uri.ToString().Split('/').Last());
var blob = container.GetBlockBlobReference(blobName);
blob.FetchAttributes();
foreach (var element in list)
{
var blob = container.GetBlockBlobReference(element);
blob.FetchAttributes();
var t = blob.Metadata;
}
知道如何在尝试访问 URL 之前对其进行编码吗?
注意:我使用最新的 Azure 存储库
【问题讨论】:
-
这个答案可能会有所帮助:stackoverflow.com/questions/1405048/…您可能只需要解码一次,但如果它不起作用,请尝试两次。 (有关非 ASP.net 的答案,请参阅 msdn.microsoft.com/en-us/library/…)
-
尝试了 WebUtility.UrlDecode(WebUtility.UrlDecode(blobName))、WebUtility.UrlDecode(blobName)、HttpUtility.UrlDecode(blobName) 等。它们都不起作用。不太确定 Blob 名称在内部是如何表示的。
标签: c# azure-blob-storage