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

Commit

Permalink
fix($http): allow sending Blob data using $http
Browse files Browse the repository at this point in the history
Closes #5012
  • Loading branch information
bbaia authored and pkozlowski-opensource committed Mar 15, 2014
1 parent 511422a commit b8cc71d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"isWindow": false,
"isScope": false,
"isFile": false,
"isBlob": false,
"isBoolean": false,
"trim": false,
"isElement": false,
Expand Down
6 changes: 6 additions & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
-isWindow,
-isScope,
-isFile,
-isBlob,
-isBoolean,
-trim,
-isElement,
Expand Down Expand Up @@ -566,6 +567,11 @@ function isFile(obj) {
}


function isBlob(obj) {
return toString.call(obj) === '[object Blob]';
}


function isBoolean(value) {
return typeof value === 'boolean';
}
Expand Down
2 changes: 1 addition & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit b8cc71d

Please sign in to comment.