سؤال

I am using a CommonsMultipartResolver for file upload.

<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 property maxUploadSize at runtime (so that the size may be changed by the administrator). What is the best way to do this please?

هل كانت مفيدة؟

المحلول

You can autowire CommonsMultipartResolver in your controller and update the property 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);
        ...
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top