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

[亡魂溺海] 提交于 2020-11-29 10:59:28

问题


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.


回答1:


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.




回答2:


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);


来源:https://stackoverflow.com/questions/60950802/how-to-download-multiple-files-in-a-single-request-from-azure-blob-storage-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!