mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix($http): Do not serialize File object
This commit is contained in:
parent
230f29d0a7
commit
5b0d068358
3 changed files with 25 additions and 1 deletions
|
|
@ -417,6 +417,11 @@ function isScope(obj) {
|
|||
}
|
||||
|
||||
|
||||
function isFile(obj) {
|
||||
return toString.apply(obj) === '[object File]';
|
||||
}
|
||||
|
||||
|
||||
function isBoolean(value) {return typeof value == $boolean;}
|
||||
function isTextNode(node) {return nodeName_(node) == '#text';}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ function $HttpProvider() {
|
|||
|
||||
// transform outgoing request data
|
||||
transformRequest: function(d) {
|
||||
return isObject(d) ? toJson(d) : d;
|
||||
return isObject(d) && !isFile(d) ? toJson(d) : d;
|
||||
},
|
||||
|
||||
// default headers
|
||||
|
|
|
|||
|
|
@ -564,6 +564,25 @@ describe('$http', function() {
|
|||
$httpBackend.expect('POST', '/url', 'string-data').respond('');
|
||||
$http({method: 'POST', url: '/url', data: 'string-data'});
|
||||
});
|
||||
|
||||
|
||||
it('should ignore File objects', function() {
|
||||
var file = {
|
||||
some: true,
|
||||
// $httpBackend compares toJson values by default,
|
||||
// we need to be sure it's not serialized into json string
|
||||
test: function(actualValue) {
|
||||
return this === actualValue;
|
||||
}
|
||||
};
|
||||
|
||||
// I'm really sorry for doing this :-D
|
||||
// Unfortunatelly I don't know how to trick toString.apply(obj) comparison
|
||||
spyOn(window, 'isFile').andReturn(true);
|
||||
|
||||
$httpBackend.expect('POST', '/some', file).respond('');
|
||||
$http({method: 'POST', url: '/some', data: file});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue