Download Image via URI (.NET Core)
public static async void GetImage(Uri uri, string filePath)
{
using(var client = new HttpClient())
{
using(var request = new HttpRequestMessage(HttpMethod.Get, uri))
{
using(Stream contentStream = await (
await client.SendAsync(request)).Content.ReadAsStreamAsync(),
stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, 3145728, true))
{
await contentStream.CopyToAsync(stream);
}
}
}
}
Comments