fix($http): allow sending Blob data using $http

Closes #5012
This commit is contained in:
Bruno Baia
2013-11-19 00:30:36 +01:00
committed by Igor Minar
parent ca7336391a
commit fbb125a3af
4 changed files with 18 additions and 1 deletions

View File

@@ -64,6 +64,7 @@
"isWindow": false,
"isScope": false,
"isFile": false,
"isBlob": false,
"isBoolean": false,
"trim": false,
"isElement": false,

View File

@@ -45,6 +45,7 @@
-isWindow,
-isScope,
-isFile,
-isBlob,
-isBoolean,
-trim,
-isElement,
@@ -566,6 +567,11 @@ function isFile(obj) {
}
function isBlob(obj) {
return toString.call(obj) === '[object Blob]';
}
function isBoolean(value) {
return typeof value === 'boolean';
}

View File

@@ -103,7 +103,7 @@ function $HttpProvider() {
// transform outgoing request data
transformRequest: [function(d) {
return isObject(d) && !isFile(d) ? toJson(d) : d;
return isObject(d) && !isFile(d) && !isBlob(d) ? toJson(d) : d;
}],
// default headers

View File

@@ -989,6 +989,16 @@ describe('$http', function() {
});
it('should ignore Blob objects', function () {
if (!window.Blob) return;
var blob = new Blob(['blob!'], { type: 'text/plain' });
$httpBackend.expect('POST', '/url', '[object Blob]').respond('');
$http({ method: 'POST', url: '/url', data: blob });
});
it('should have access to request headers', function() {
$httpBackend.expect('POST', '/url', 'header1').respond(200);
$http.post('/url', 'req', {