Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit fbb125a

Browse files
bbaiaIgorMinar
authored andcommitted
fix($http): allow sending Blob data using $http
Closes #5012
1 parent ca73363 commit fbb125a

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/.jshintrc

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"isWindow": false,
6565
"isScope": false,
6666
"isFile": false,
67+
"isBlob": false,
6768
"isBoolean": false,
6869
"trim": false,
6970
"isElement": false,

src/Angular.js

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
-isWindow,
4646
-isScope,
4747
-isFile,
48+
-isBlob,
4849
-isBoolean,
4950
-trim,
5051
-isElement,
@@ -566,6 +567,11 @@ function isFile(obj) {
566567
}
567568

568569

570+
function isBlob(obj) {
571+
return toString.call(obj) === '[object Blob]';
572+
}
573+
574+
569575
function isBoolean(value) {
570576
return typeof value === 'boolean';
571577
}

src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function $HttpProvider() {
103103

104104
// transform outgoing request data
105105
transformRequest: [function(d) {
106-
return isObject(d) && !isFile(d) ? toJson(d) : d;
106+
return isObject(d) && !isFile(d) && !isBlob(d) ? toJson(d) : d;
107107
}],
108108

109109
// default headers

test/ng/httpSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,16 @@ describe('$http', function() {
989989
});
990990

991991

992+
it('should ignore Blob objects', function () {
993+
if (!window.Blob) return;
994+
995+
var blob = new Blob(['blob!'], { type: 'text/plain' });
996+
997+
$httpBackend.expect('POST', '/url', '[object Blob]').respond('');
998+
$http({ method: 'POST', url: '/url', data: blob });
999+
});
1000+
1001+
9921002
it('should have access to request headers', function() {
9931003
$httpBackend.expect('POST', '/url', 'header1').respond(200);
9941004
$http.post('/url', 'req', {

0 commit comments

Comments
 (0)