How to download multiple files in a single request from Azure Blob Storage using c#?

Viewed 8744

I need to download 1000 small images from my Azure Blob Storage. I don't want to make a separate request for each file. How to do this in c#?

Right now I am using Azure.Storage.Blobs and Azure.Storage.Blobs.Batch but neither of them have this API. The latter one has only DeleteBlobs call at the moment of posting this question.

2 Answers

I need to download 1000 small images from my Azure Blob Storage. I don't want to make a separate request for each file. How to do this in c#?

Unfortunately there's no batch download capability available in Azure Blob Storage. You will need to download each blob individually. What you could do is download blobs in parallel to speed things up.

You could speed up the download by downloading in parallel.

var semaphore = new SemaphoreSlim(100);
List<Task> downloadTasks = new List<Task>();
foreach (var fileName in fileNames)
{
    await semaphore.WaitAsync();
    downloadTasks.Add(Task.Run(async () =>
    {
        // here download the file
        semaphore.Release();
    }));
}
await Task.WhenAll(downloadTasks);
Related