我通過使用控制器定義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");
});
}