Reputation: 5162
I am trying to retrieve all image files from a virtual directory in my Azure storage account. The path of the folder (container URI) is correct but is returning
StorageException: The requested URI does not represent any resource on the server.
Pasting the URI in the browser produces
BlobNotFound
The specified blob does not exist. RequestId:622f4500-a01e-0022-7dd0-7d9428000000 Time:2019-10-08T12:02:29.6389180Z
The URI, which is public, works fine; you can see this video by pasting the URI in your browser or clicking the Engine Video link below.
My code grabs the container, whose URI is https://batlgroupimages.blob.core.windows.net/enerteck/publicfiles/images/robson
public async Task<List<string>> GetBlobFileListAsync(CloudBlobContainer blobContainer, string customer)
{
var files = new List<string>();
BlobContinuationToken blobContinuationToken = null;
do
{
//code fails on the line below
var segments = await blobContainer.ListBlobsSegmentedAsync(null, blobContinuationToken);
blobContinuationToken = segments.ContinuationToken;
files.AddRange(segments.Results.Select(x => GetFileNameFromBlobUri(x.Uri, customer)));
} while (blobContinuationToken != null);
return files;
}
The code is failing on the var segments = await blobContainer…. code line and it is not the container that is causing the error (IMO) as you can see the container comes back with a valid URI
and the virtual folder contains files
I would love to know what I am doing wrong here.
Upvotes: 2
Views: 4900
Reputation: 5162
So the answer lies in the fact that I am trying to list blobs WITHIN a virtual folder path So in the OP, I was trying to list the blobs using the FULL path to the folder containing the blobs. You cannot do it that way. You must use one of the overloads of ListBlobsSegmentedAsync on the MAIN CONTAINER. Thanks to juunas for getting me to realize I wasn't starting at the main container. I realized their must be other overload methods to accomplish what I was seeking to do
The code below works well
public async Task<List<EvaluationImage>> GetImagesFromVirtualFolder(CloudBlobContainer blobContainer, string customer)
{
var images = new List<EvaluationImage>();
BlobContinuationToken blobContinuationToken = null;
do
{
//this is the overload to use, you pass in the full virtual path from the main container to where the files are (prefix), use a
//useflatbloblisting (true value in 2nd parameter), BlobListingDetail, I chose 100 as the max number of blobs (parameter 4)
//then the token and the last two parameters can be null
var results = await blobContainer.
ListBlobsSegmentedAsync("publicfiles/images/" + customer,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);
var img = new EvaluationImage
{
ImageUrl = item.Uri.ToString(),
ImageCaption = GetCaptionFromFilename(filename),
IsPosterImage = filename.Contains("poster")
};
images.Add(img);
}
} while (blobContinuationToken != null);
return images;
}
Upvotes: 0
Reputation: 58733
https://batlgroupimages.blob.core.windows.net/enerteck/publicfiles/images/robson
is not a container URI.
https://batlgroupimages.blob.core.windows.net/enerteck
is a container URI.
publicfiles/images/robson/image.png
could be a blob's name in that container.
I'm thinking you may have included some of the virtual folder path in the container URI and maybe that is messing up something?
Upvotes: 1