How to limit the size of a multi-page file in a java controller

I have a break controller method that receives the multipart file parameter, I need to limit its restriction on file size. I tried different options, but it does not work for me. I am using Apache Tomcat 8. I am calling the rest method using a windows service.

Following the definition of the class and method:

@Controller
public class MyClass{
     ...
}

@RequestMapping(value = "/path/method/param1/{param1}/param2/{param2}/", 
                method = RequestMethod.POST)
public ResponseEntity<String> method(DTO dto, @RequestParam("file") MultipartFile multipartFile){
    ...
}

Proven solutions:

  • Adding node to web.xml
<multipart-config>
   <max-file-size>52428800</max-file-size>
   <max-request-size>52428800</max-request-size>
   <file-size-threshold>0<</file-size-threshold>
</multipart-config>
  1. Adding the maxPostSize and maxSwallowSize properties to the node connector in the server.xml file

  2. Adding size parameters to a .properties file

  3. Adding @MultipartConfig annotation in the controller class

Any idea or suggestions?

+4
source share
1 answer

spring-servlet.xml, , bean org.springframework.web.multipart.commons.CommonsMultipartResolver,

+2

Source: https://habr.com/ru/post/1694865/


All Articles