springboor ant design vue上传大文件失败 ,或者一般大小的也会失败
前端
/**
* 上传 axios
*/
export function getBackupUpload(parameter) {
console.log(parameter)
return axios({
url: '/main/selectBackup/upload',
method: 'post',
headers: {
'content-Type': 'multipart/form-data'
},
data: parameter,
})
}
// 自定义上传,不用通过action属性
customRequest(file) {
this.uploadLoading=true
console.log(file)
const form = new FormData()
form.append('file', file.file)
form.append('contractName', file.file.name)
form.append('description', file.file.name)
//自定义上传接口
getBackupUpload(form).then(res => {
console.log(res)
this.$message.success('操作成功,文件恢复中,请耐心等待')
this.uploadLoading=false
}).catch(err => {
console.log(err)
this.$message.error('文件不符合规范,已删除')
this.uploadLoading=false
})
},
后端
@PostMapping(value = "/upload")
public ResponseData uploadFile(@RequestParam("file") MultipartFile file) throws IOException, InterruptedException {
if (file.isEmpty()) {
// return "未选择文件";
}
String fileName = file.getOriginalFilename();
System.out.println("接收上传文件");
System.out.println(str);
String path = "C:\\Users\\x\\Desktop\\";
System.out.println(path+""+str);
file.transferTo(new File(path+fileName));
return new SuccessResponseData(200, "执行成功", "");
}