I am trying to create a function for all blobs in a container. I took the help
How to get hold of all the blobs in a Blob container which has sub directories levels(n levels)?, which seems to use an overload that doesn't exist any more. I had added default values into the additional fields prefix
and operationContext
:
static internal async Task<List<string>> ListBlobNames(string ContainerName)
{
BlobContinuationToken continuationToken = null;
bool useFlatBlobListing = true;
BlobListingDetails blobListingDetails = BlobListingDetails.None;
var blobOptions = new BlobRequestOptions();
CloudBlobContainer container = Container(ContainerName);
var operationContext = new OperationContext();
var verify = container.GetBlobReference("A_Valid_Name.jpg");
var verify2 = container.GetBlobReference("NotAName.jpg");
using (var a = await verify.OpenReadAsync()) ;
//using (var a = await verify2.OpenReadAsync()); // doesn't work since it doesn't exist
return (await container.ListBlobsSegmentedAsync("", useFlatBlobListing, blobListingDetails, null, continuationToken, blobOptions, operationContext))
.Results.Select(s => s.Uri.LocalPath.ToString()).ToList();
}
The last line gave me an exception:
StorageException: The requested URI does not represent any resource on the server.
I then created the verfiy
and verify2
variables to test if my container is valid. verify
references a valid blob and verify2
references an invalid blob name. Running the code with the second using statement uncommented gave me an error in the second using statement. This shows that the verify
works and thus the container is valid.