Modifying CommonsMultipartResolver maxUploadSize at Run Time

I am using CommonsMultipartResolver to upload files.

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" > <!-- specify maximum file size in bytes --> <property name="maxUploadSize" value="100000"/> </bean 

I want to be able to change its maxUploadSize property at runtime (so that the size can be changed by the administrator). What is the best way to do this, please?

+3
java spring spring-mvc file-upload apache-commons-fileupload
source share
1 answer

You can autowire CommonsMultipartResolver in your controller and update it there at runtime.

For example:

 @Controller public class MyController { @Autowired private CommonsMultipartResolver multipartResolver; @RequestMapping(value = "/setMaxUploadSize", method = RequestMethod.GET) public ModelAndView setMaxUploadSize() { ... multipartResolver.setMaxUploadSize(5000); ... } } 
+6
source share

All Articles