I'm sorry if this question has been answered before, but none of the answers helped me. I have an event for my WebView:
private async void MainWebView_UnviewableContentIdentified(WebView sender, WebViewUnviewableContentIdentifiedEventArgs args)
{
await downloadFromUri(args.Uri).ConfigureAwait(false);
}
My downloadFromUri method will attempt to download a file and store it in the downloads folder and finally it will open the file:
static async Task downloadFromUri(Uri uri)
{
var url = uri;
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.TryAppendWithoutValidation(
"Authorization Bearer",
" MYTOKEN"
);
Debug.WriteLine("Attempting GET request");
var response = await client.GetAsync(url);
Debug.WriteLine("Got response.. checking " + response.StatusCode);
if (response.IsSuccessStatusCode)
{
Debug.WriteLine("Okay, we've got a response");
var responseFileName = response.Content.Headers.ContentDisposition.FileName;
Debug.WriteLine("Filename: " + responseFileName);
var ManualFile = await DownloadsFolder.CreateFileAsync(responseFileName, CreationCollisionOption.GenerateUniqueName);
Debug.WriteLine("Creating buffer: ");
var buffer = await client.GetBufferAsync(url);
Debug.WriteLine("Writing buffer.");
await Windows.Storage.FileIO.WriteBufferAsync(ManualFile, buffer);
Debug.WriteLine("Done, opening");
var openOptions = new Windows.System.LauncherOptions();
openOptions.DisplayApplicationPicker = true;
var openFile = await Windows.System.Launcher.LaunchFileAsync(ManualFile, openOptions);
}
else
{
Debug.WriteLine(response.StatusCode.ToString());
}
}
The thing is, this code seems to work fine on small PDF or zip files. But when it comes to PDF files that are > 10mb, the application just hangs at the following line:
var response = await client.GetAsync(url);
What can I do to make this work? Thanks a lot in advance!
Note: I'm using the Windows.Web.Http.HttpClient and not the System.Net.Http.HttpClient.
Edit: I've tried to skip the client.GetAsync(url)
and run the var buffer = await client.GetBufferAsync(url);
directly. This also returns in a hang.