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

Commit 02674fc

Browse files
committed
fix($http) Don't try to JSON.stringify FormData objects
This won't enable FormData uploads in itself, as the Content-Type is automatically set to application/json.
1 parent 6ad109e commit 02674fc

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/Angular.js

+4
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ function isFile(obj) {
565565
return toString.call(obj) === '[object File]';
566566
}
567567

568+
function isFormData(obj) {
569+
return toString.call(obj) === '[object FormData]';
570+
}
571+
568572

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

src/ng/http.js

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

143143
// transform outgoing request data
144144
transformRequest: [function(d) {
145-
return isObject(d) && !isFile(d) && !isBlob(d) ? toJson(d) : d;
145+
return isObject(d) && !isFile(d) && !isBlob(d) && !isFormData(d) ? toJson(d) : d;
146146
}],
147147

148148
// default headers

test/ng/httpSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,15 @@ describe('$http', function() {
991991
$http({ method: 'POST', url: '/url', data: blob });
992992
});
993993

994+
it('should ignore FormData objects', function() {
995+
if (!window.Blob) return;
996+
997+
var formData = new FormData();
998+
formData.append('angular', 'is great');
999+
1000+
$httpBackend.expect('POST', '/url', '[object FormData]').respond('');
1001+
$http({ method: 'POST', url: '/url', data: formData });
1002+
});
9941003

9951004
it('should have access to request headers', function() {
9961005
$httpBackend.expect('POST', '/url', 'header1').respond(200);

0 commit comments

Comments
 (0)