我通过使用控制器定义RequestPart注释,
由于https://stackoverflow.com/a/30043173/3121941得到了解决。它为我提供了解决问题的见解。
更新的代码,
@RequestMapping(value = "/someUrl", method = RequestMethod.POST, consumes = {
"multipart/form-data", MediaType.APPLICATION_JSON_VALUE })
public Object handleUpload(
@RequestPart("paramOne") String paramOne,
@RequestPart("paramTwo") String paramTwo,
@RequestPart("file") MultipartFile file, Principal user){
和我的角码,
$scope.upload = function() {
var file = $scope.file;
var obj = new Object();
var fd = new FormData();
fd.append("paramOne","xyz");
fd.append("paramTwo","xyz");
fd.append("file", file);
var uploadUrl = "/someUrl";
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {
'Content-Type': undefined
}
}).success(function (data) {
console.log("Call successful");
});
}