Sunday, March 10, 2013

Chrome’s XMLHttpRequest (XHR ) abort issue while uploading multiple files.

I developed a file uploading component using HTML5 File API and XMLHttpRequest(XHR) .One of the main requirements was, the user should be able to abort/cancel one or more uploading request from the list of files that are being uploaded.

Please check my previous post of “How to Upload Files with HTML5 File API and XMLHttpRequest(XHR)”

While I was implementing abort functionality, I came across an issue that the Chrome Browser did not allow aborting a request when multiple files are being uploaded. And this turned out to be a bug

The bug reports explain that it’s something to do with cached resource. So it tried to make every POST request to be unique. As I don’t allow the user to select files that has same names, I was able to make the XHR request unique with appending the file name in each request.

The initial one was:'POST', "", true);

After the modification:'POST', "?upid=" +, true);
here, ‘upid’ is just a parameter name that I use .

So the code that makes the XHR request would be
if ($ {
 try {
   * XHR.abort() is not working properly in Chrome ( aborting
   * a file upload while uploading multiple files parallely)
  // Bug
  // :
  // Bug :
  // Bug :'POST', "?upid=" +, true);
 } catch (e) {
} else {'POST', "", true);
This approach really worked for me and hope it helps you too