使用FormData对象。示例如下:
HTML代码:
AngularJS代码:
$scope.submit = function() { var file = $scope.data.file; var formData = new FormData(); formData.append('file', file); formData.append('name', $scope.data.name);
$http.post('/upload', formData, { transformRequest: angular.identity, headers: {'Content-Type': undefined} }) .success(function(response) { console.log(response); }) .error(function(response) { console.log(response); }); };
注意事项: