angular-file-upload-shim does not work correctly on Chrome - Failed to execute 'setRequestHeader' on 'XMLHttpRequest'
See original GitHub issueWhen I try to upload a file, I get this error:
Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'function (xhr) {
if (!xhr) return;
config.__XHR = xhr;
config.xhrFn && config.xhrFn(xhr);
xhr.upload.addEventListener('progress', function(e) {
e.config = config;
deferred.notify ? deferred.notify(e) : promise.progress_fn && $timeout(function(){promise.progress_fn(e)});
}, false);
//fix for firefox not firing upload progress end, also IE8-9
xhr.upload.addEventListener('load', function(e) {
if (e.lengthComputable) {
e.config = config;
deferred.notify ? deferred.notify(e) : promise.progress_fn && $timeout(function(){promise.progress_fn(e)});
}
}, false);
}' is not a valid HTTP header field value.
What I figured out is that $upload
sets a fake header called __setXHR_
and angular-file-upload-shim
patches some methods to manage the fake header here:
patchXHR('setRequestHeader', function(orig) {
return function(header, value) {
if (header === '__setXHR_') {
initializeUploadListener(this);
var val = value(this);
// fix for angular < 1.2.0
if (val instanceof Function) {
val(this);
}
} else {
this.__requestHeaders = this.__requestHeaders || {};
this.__requestHeaders[header] = value;
orig.apply(this, arguments);
}
}
});
The problem is that angular-file-upload-shim
conditionally executes most of its code:
if ((window.XMLHttpRequest && !window.FormData) || (window.FileAPI && FileAPI.forceLoad))
And at least in my browser (Chrome 40.0.2214.93 for Linux), window.FormData is set, and window.FileAPI is not, so the condition isn’t met.
In summary:
- The fake header is set
- The patched XHR function that would process the fake header is not set.
- The core javascript libraries cannot process the fake header and everything stops working
Versions:
- angular 1.3.12
- ng-file-upload 3.0.7
Issue Analytics
- State:
- Created 9 years ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Failed to execute 'setRequestHeader' on 'XMLHttpRequest ...
I had faced this problem. Please make sure that in your code header name doesn't contain space. i.e. 'designId ' is invalid, as...
Read more >Tm1-ui-upload libs.3.0.1.js:9576 DOMException: Failed to ...
Issue: angular-file-upload-shim does not work correctly on Chrome - Failed to execute 'setRequestHeader' on 'XMLHttpRequest'.
Read more >'Authorization: Bearer ' is not a valid HTTP header field name
Chrome is giving the Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Authorization: Bearer ' is not a valid HTTP header field name ...
Read more >Fix Chrome update problems & failed updates - Google Support
If you're having problems updating Chrome on your computer, you might see: Update failed: Updates are disabled by administrator Update failed (Error: 3...
Read more >Failed to execute 'setRequestHeader' on 'XMLHttpRequest'
... in angular but give an error Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Access- Control - Allow - Methods' is not a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Loading “ng-file-upload.js” before loading “pace.js” fixed the issue for me.
Hi, how did you guys work out that it is was Pace.js ? I’m not using pace.js but I’m receiving this error, and trying to work out what is the conflict.