Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have the following code written to list blobs in a container as part of a controller api.
public async Task<IDictionary<string, string>> ListBlobsWithContentAsync(string container)
{
ArgumentException.ThrowIfNullOrWhiteSpace(container);
var list = new Dictionary<string, string>();
var containerClient = client.GetBlobContainerClient(container);
var blobs = await ListBlobsFlatListingAsync(containerClient, 50);
foreach (var blob in blobs)
{
var blobInfo = await GetBlobDownloadResultAsync(containerClient, blob).ConfigureAwait(false);
using StreamReader reader = new(blobInfo.Value.Content);
string blobContent = await reader.ReadToEndAsync().ConfigureAwait(false);
list.Add(blob, blobContent);
}
return list;
}
private static async Task<IList<string>> ListBlobsFlatListingAsync(BlobContainerClient blobContainerClient,
int? segmentSize)
{
var list = new List<string>();
// Call the listing operation and return pages of the specified size.
var resultSegment = blobContainerClient.GetBlobsAsync()
.AsPages(default, segmentSize);
// Enumerate the blobs returned for each page.
await foreach (var blobPage in resultSegment)
{
foreach (var blobItem in blobPage.Values)
{
list.Add(blobItem.Name);
}
}
return list;
}
What is wrong with this code and what can I do to fix this?.