File uploader component not triggering onUploadProgress in Blazor WASM hosted on IIS

Mohan Raj 0 Reputation points
2023-03-06T13:10:27.2333333+00:00

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);
}


Developer technologies | .NET | Blazor
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.