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

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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