File uploader component not triggering onUploadProgress in Blazor WASM hosted on IIS
I'm using a file uploader component in Blazor WebAssembly and I've implemented the upload action in JavaScript. The file upload works fine when I run the sample locally, but when I host the sample in IIS, the ajax Upload Progress
event function doesn't trigger and I don't get the progress bar. I've checked the console and there are no errors.
I've also checked my server configuration and made sure that the maximum allowed file size is greater than the file I'm trying to upload.
What could be causing the ajax Upload Progress
event function to not trigger when the sample is hosted in IIS?
Here's the code snippet I'm using in my JavaScript:
// JavaScript code for file upload
function uploadFile() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/api/upload", true);
xhr.upload.onprogress = function(event) {
if (event.lengthComputable) {
var percentComplete = (event.loaded / event.total) * 100;
console.log(percentComplete + '% uploaded');
}
};
xhr.onload = function() {
if (this.status === 200) {
console.log('Upload completed successfully');
}
else {
console.log('Upload failed');
}
};
xhr.send(formData);
}