Java &引用;当前请求不是多部分请求”;angularjs和弹簧靴
我知道这个问题已经被问了一遍又一遍,但是在尝试了所有可能的选择之后,我仍然得到了这个错误:Java &引用;当前请求不是多部分请求”;angularjs和弹簧靴,java,angularjs,spring,spring-boot,Java,Angularjs,Spring,Spring Boot,我知道这个问题已经被问了一遍又一遍,但是在尝试了所有可能的选择之后,我仍然得到了这个错误: 当前请求不是多部分请求 以下是我在angular中的代码: app.controller("controller", function ($scope, $http, $window, $log) { $scope.upload = function () { var file = $scope.myFile; var fd = new FormData();
当前请求不是多部分请求
以下是我在angular中的代码:
app.controller("controller", function ($scope, $http, $window, $log) {
$scope.upload = function () {
var file = $scope.myFile;
var fd = new FormData();
fd.append('file', file);
$http.post('upload', fd, {
transformRequest: angular.identity,
})
.success(function(){
})
.error(function(){
});
};
控制器代码:
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public Callable<FileUpload> uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
parser = fileHandlerService.getParser(file);
Callable<FileUpload> asyncResult = new Callable<FileUpload>() {
@Override
public FileUpload call() throws Exception {
FileUpload fileUpload = fileHandlerService.getUploadStatus();
return fileUpload;
}
};
return asyncResult;
}
@RequestMapping(value=“/upload”,method=RequestMethod.POST)
公共可调用上载文件(@RequestParam(“文件”)MultipartFile文件)引发异常{
parser=fileHandlerService.getParser(文件);
Callable asyncResult=new Callable(){
@凌驾
public FileUpload调用()引发异常{
FileUpload FileUpload=fileHandlerService.getUploadStatus();
返回文件上传;
}
};
返回结果;
}
HTML代码:
<div class="vertical-center">
<input type="file" file-model="myFile">
<button ng-click="upload()" class="btn btn-primary btn-lg">Upload
</button>
</div>
上载
我尝试放置:headers:{'Content-Type':undefined}
但是添加header后,我不再得到错误500,而是得到错误400
我通过Postman
发送文件,没有任何标题,而且工作正常。所以我不明白为什么它不能通过角度
提前感谢。除了添加标题:{'Content-Type':undefined},还可以将div更改为表单,并将enctype=“multipart/form data”添加到表单中。i、 你的代码看起来像
<form class="vertical-center" enctype="multipart/form-data">
<input type="file" file-model="myFile">
<button ng-click="upload()" class="btn btn-primary btn-lg">Upload
</button>
</form>
上载