问题
I'm trying to get file upload progress inside a blazor web assembly app.
var handler = new ProgressMessageHandler();
handler.InnerHandler = new WebAssemblyHttpMessageHandler();
handler.HttpSendProgress += (object sender, HttpProgressEventArgs e) =>
{
Console.WriteLine("bytes transfered= " + e.BytesTransferred.ToString());
Console.WriteLine("total bytes= " + e.TotalBytes.ToString());
Console.WriteLine("progress percentage= " + e.ProgressPercentage.ToString());
};
var http = new HttpClient(handler);
http.BaseAddress = new Uri(NavigationManager.BaseUri);
await http.PostJsonAsync("api/...", attachedFile);
Console.WriteLine("Done");
I came up with the following code, but when I upload a file I get a single event instantly reporting 100% completion even if the post request last a few seconds.
WASM: bytes transfered= 277983
blazor.webassembly.js:1 WASM: total bytes= 277983
blazor.webassembly.js:1 WASM: progress percentage= 100
There is a few questions on SO dealing with upload progress but I want to use the Http.ProgressMessageHandler if possible
来源:https://stackoverflow.com/questions/58095977/upload-progress-using-httpclient-in-blazor-wasm