Provides a flexible utility for downloading files from specified URIs, with thread-safe concurrency and automatic file name conflict handling
$ dotnet add package Soenneker.Utils.File.Download
Soenneker.Utils.File.Downloaddotnet add package Soenneker.Utils.File.Download
IFileDownloadUtil within DI (Program.cs).public static async Task Main(string[] args)
{
...
builder.Services.AddFileDownloadUtilAsScoped();
}
IFileDownloadUtilExample:
public class TestClass
{
private readonly IFileDownloadUtil _util;
public TestClass(IFileDownloadUtil util)
{
_util = util;
}
public async ValueTask Download()
{
string directory = "path/to/save/files";
List<string> uris = new List<string>
{
"https://example.com/file1.jpg",
"https://example.com/file2.jpg",
"https://example.com/file3.jpg"
};
int maxConcurrentDownloads = 3;
List<string> downloadedFiles = await _util.DownloadFiles(directory, uris, maxConcurrentDownloads);
}
}