pg2727
pg2727

Reputation: 179

Azure Blob Storage Issue with downloading a file

I'm working on functionality to allow users to download Azure Blob Storage items.

I am trying to get a list of blobs using:

 var list = await container.GetBlobsAsync(BlobTraits.All, BlobStates.All, string.Empty).ConfigureAwait(false);

Here is the error I have though:

Error CS1061 'ConfiguredCancelableAsyncEnumerable' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'ConfiguredCancelableAsyncEnumerable' could be found (are you missing a using directive or an assembly reference?)

Is async available for C# 7.3? Or to use Async calls to obtain all the blobs in the container I need to upgrade to 8.0 C#?

If I change the code to this:

            await foreach (BlobItem page in container.GetBlobsAsync(BlobTraits.None, BlobStates.None, string.Empty))
            {
                yield return container.GetBlobClient(page.Name);
            }

Then I have this error:

Error CS8370 Feature 'async streams' is not available in C# 7.3. Please use language version 8.0 or greater.

I know GetBlobsAsync() returns AsyncPageable<> and I'm assuming it is only available in C# 8.0?

Upvotes: 6

Views: 4999

Answers (1)

Sam Baude
Sam Baude

Reputation: 136

These are the 2 options I can think of :

  1. update you're langVersion to 8 which you are saying you do not want to do
  2. use an enumerator eg

    var blobs = blobContainerClient.GetBlobsAsync()
    List<BlobItem> blobList = new List<BlobItem>();
    IAsyncEnumerator<BlobItem> enumerator = blobs.GetAsyncEnumerator();
    try
    {
        while (await enumerator.MoveNextAsync())
        {
            blobList.Add(enumerator.Current);
        }
    }
    finally
    {
        await enumerator.DisposeAsync();
    }
    

Upvotes: 11

Related Questions