0

I have bunch of blobs on azure storage which follow name in following pattern: <someName>_DateTimeOffset.UtcNow. When I fetch the blobs using container.ListBlobs() the blob Uri looks like this: <someName>__11%252f3%252f2014+10%253a00%253a00+PM+%252b00%253a00+%252b00%253a00.

If you look closely, %25 becomes % when encoded once and %2f becomes :. So it looks like the Uri goes through double encoding.

When I try to get hold of this blob, it doesn't work. Here is the code snippet:

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;
        }

Any Idea how do I encode the URL before trying to access it?

Note: I use latest azure storage library

Amit
  • 25,106
  • 25
  • 75
  • 116
  • This answer may help: http://stackoverflow.com/questions/1405048/how-do-i-decode-a-url-parameter-using-c You probably only need to decode once, but try twice if it doesn't work. (See http://msdn.microsoft.com/en-us/library/system.net.webutility.urlencode(v=vs.110).aspx for non-ASP.net answer) – dodald Nov 06 '14 at 20:15
  • tried WebUtility.UrlDecode(WebUtility.UrlDecode(blobName)), WebUtility.UrlDecode(blobName), HttpUtility.UrlDecode(blobName) etc. none of them work. Not so sure how blob name is represented internally. – Amit Nov 06 '14 at 20:36

1 Answers1

0

Instead of trying to get a blob reference, we can just convert the ListBlob result to ICloudBlob and call delete on it. Here is the code:

var l= resultSegment.Results.Select(x => x as ICloudBlob);
foreach (var cloudBlob in l)
        {
            cloudBlob.Delete();
        }
Amit
  • 25,106
  • 25
  • 75
  • 116