public async Task DownloadImage(Credential creds, Guid sourceId, string imageId, string imageUrl, string token, string downloadPath, string[] tokenUrls) { if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } IFlurlRequest url = new FlurlRequest(imageUrl); if (tokenUrls.Any(turl => new Uri(imageUrl).Host == turl)) { url = imageUrl.WithOAuthBearerToken(token); } var response = await url.GetBytesAsync(); File.WriteAllBytes(Path.Combine(downloadPath, imageId.ToString()), response); }