Reputation: 429
Assembly in use: Assembly Microsoft.WindowsAzure.Storage, Version=9.3.1.0
What I want to do: In my Azure storage, I have images stored as a blob, in the following fashion
I want to get the URLs of all the image blobs along with their last modified timestamp.
Please note that Image1
and Image4
might have the same name.
What I have tried:
I tried ListBlobsSegmentedAsync(BlobContinuationToken currentToken)
from the root of the container and by using GetDirectoryReference(string relativeAddress)
but couldn't get the desired result.
Though a bit off track, I am able to get the blob details by GetBlockBlobReference(string blobName);
What should I do?
Thanks in advance.
Upvotes: 1
Views: 791
Reputation: 20127
The ListBlobsSegmentedAsync
method has 2 overloads that contain the useFlatBlobListing
argument. These overloads accept 7 or 8 arguments, and I count 6 in your code.
Use the following code to list all blob in container.
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);
}
}
The result is as below:
Upvotes: 1
Reputation: 136394
Please try this override of ListBlobsSegmentedAsync
with the following parameters:
prefix: ""
useFlatBlobListing: true
blobListingDetails: BlobListingDetails.All
maxResults: 5000
currentToken: null or the continuation token returned
This will return you a list of all blobs (including inside virtual folders)
Upvotes: 0