jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.13k stars 270 forks source link

Upload progress event not called #192

Open josefguenther opened 8 years ago

josefguenther commented 8 years ago

I cannot get the upload progress event to work.

Here's my code:

var xhr = new XMLHttpRequest();
xhr.open('PUT', '/asset/1', true);
xhr.addEventListener("load", () => {
  console.log("done");
});
xhr.upload.addEventListener("progress", (e) => {
  console.log("upload progress");
});
xhr.addEventListener("progress", (e) => {
  console.log("main progress");
});
xhr.send(data);

I get the following result:

PUT ................
main progress
done

If I inspect the e variable on the main progress listener (it is only called ONCE), it is always the same; important parts below:

isTrusted: false,
lengthComputable: false,
loaded: 68,
total: 68

Don't ask me why it's always 68 regardless of file size. I also tried xhr.upload.onProgress() and xhr.upload.on("progress", ...).

Just a side note: the progress was working perfectly before implementing xdomain; I was using xhr.upload.onProgress().

Any ideas?

josefguenther commented 8 years ago

Ok, figured out the "main progress" event: it is the download of data after upload. The server response is always 68 bytes in my case.

Upload events however are not called.