java - 如何配置Spring Boot每个Controller控制不同的文件上传大小最大值?
伊谢尔伦
伊谢尔伦 2017-04-18 10:48:48
0
1
639

我知道有一个配置项multipart.max-file-size可以控制文件上传大小,但这个值为一全局配置无法细化到每个Controller,而使用MultipartFile类的getSize()方法判断大小的话文件必然已经全部上传到服务器了,我需要一个类似multipart.max-file-size配置项的效果,如果文件超出指定大小后直接中断请求,并能在每一个Controller中进行不同值得设置,谢谢。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
Peter_Zhu

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;
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!