我正在使用带有tomcat 8的spring MVC 4.在上传文件时我收到以下错误。我已将会话配置为在一小时后过期。任何人都可以指导我正确的方向
Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. null] with root cause
java.net.SocketTimeoutException
at org.apache.tomcat.util.net.NioBlockingSelector.read(NioBlockingSelector.java:201)
at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:235)
at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:216)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1233)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1182)
at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:708)
at org.apache.coyote.http11.Http11InputBuffer.access$300(Http11InputBuffer.java:40)
at org.apache.coyote.http11.Http11InputBuffer$SocketInputBuffer.doRead(Http11InputBuffer.java:1057)
at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:139) ...
在控制器中:
@PostMapping(value = "/uploadSurvey")
@ResponseBody
public String uploadSurvey(@Valid FileBucket fileBucket, BindingResult result, HttpSession session) {
if (result.hasErrors())
return "redirect:/surveys/uploadSurvey";
else {
byte[] bytes;
try {
bytes = fileBucket.getFile().getBytes();
String decoded = new String(bytes, "UTF-8");
//Here I do object mapping using jackson
}
catch (Exception e){
e.printStackTrace();
}
}
return "xxx";
}
在客户端我使用angularjs发送文件:
fd.append('file', file);
fd.append($scope.csrfParamName, $scope.csrfToken);
$http.post(uploadUrl, fd, {
transformRequest : angular.identity,
headers : {
'Content-Type' : undefined
}
})