各位大神,当我使用jQuery AJAX进行异步上传文件时,后台 Spring MVC 控制器给我报错如下:
Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found.
以下是相关的代码片段:
$('#fileUpload').on('change', function(){
if(!this.value) return;
var formData = new FormData();
formData.append(this.name, this.files[0]);
$.ajax({
type: 'POST',
url: '/file/upload',
dataType: 'json',
data: formData,
processData: false,
contentType: 'multipart/form-data',
success: function(json){
console.log(json);
},
error: function (jqXHR, textStatus, errorMsg) {
// ignore
}
});
});
/**
* 上传文件
*/
@PostMapping("/file/upload")
public String upload(MultipartFile file) {
// 还没进入下面的代码就报错了
}
环境信息
- jQuery 1.11.1
- 浏览器:Chrome 69
- 后台 Spring MVC 4.3.18.RELEASE