Willcode4cash icon

Download Image via URI (.NET Core)

Willcode4cash | PRO | 06/22/17 09:27:41 AM UTC | 0 ⭐ | 213 👁️ | Never ⏰ | []
C# |

540 B

|

None

|

0 👍

/

0 👎

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