Linas Linas - 1 year ago 90
Javascript Question

Ajax file upload progress event not firing

I am uploading a file via ajax request, by simply splitting them in to chunks.

The problem is progress event, Firefox for some reason doesn't want to fire that event, here is my code (most of the unnecessary code is removed)

//slice file
chunk = file.mozSlice(startByte, endByte);
}else if(file.slice){
chunk = file.slice(startByte, endByte);
chunk = file;
isLast = true;

var xhr = new XMLHttpRequest();

xhr.upload.addEventListener('progress', function(e){
}, false);

xhr.upload.addEventListener('error', function(e){
console.log("upload error!");

xhr.onreadystatechange = function(e){
if(this.readyState == 4 && this.status == 200){
//this chunk has bee uploaded, proceed with the next one...
}'POST', "", true);

xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');//header
xhr.setRequestHeader('Content-Type', 'application/octet-stream');//generic stream header

I'm sure i haven't made any big mistakes since chrome works without any problems, so there must be some Firefox related issue.

Answer Source

I checked my implementation I'm adding the progress event after I call, maybe that fixes it?

Try the 2nd code sample here: does that work?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download