我知道有一个配置项multipart.max-file-size可以控制文件上传大小,但这个值为一全局配置无法细化到每个Controller,而使用MultipartFile类的getSize()方法判断大小的话文件必然已经全部上传到服务器了,我需要一个类似multipart.max-file-size配置项的效果,如果文件超出指定大小后直接中断请求,并能在每一个Controller中进行不同值得设置,谢谢。
天蓬老师2017-04-18 10:50:48
Provide a solution
Use multipart.max-file-size to configure the maximum file upload size=>Then get the size of the uploaded file in the code=>Judge whether the conditions are met
Pseudo code:
Boolean upload(String path,File file,Integer maxSize){
Intege fileSize = file.size();
if(fileSize<=maxSize){
//上传...
return true;
}else{
return false;
}
}