I have a Spring MVC website with two different pages that have different forms for uploading different files. One of them should have a 2 MB limit, and the other should have a 50 MB limit.
Right now, I have this limitation in my app-config.xml:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="2097152 "/> </bean>
And I could solve the maxUploadSize exception in my main controller as follows:
@Override public @ResponseBody ModelAndView resolveException(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception exception) { ModelAndView modelview = new ModelAndView(); String errorMessage = ""; if (exception instanceof MaxUploadSizeExceededException) { errorMessage = String.format("El tamaño del fichero debe ser menor de %s", UnitConverter.convertBytesToStringRepresentation(((MaxUploadSizeExceededException) exception) .getMaxUploadSize())); } else { errorMessage = "Unexpected error: " + exception.getMessage(); } saveError(arg0, errorMessage); modelview = new ModelAndView(); modelview.setViewName("redirect:" + getRedirectUrl()); } return modelview; }
But this obviously only controls a 2 MB limit. How can I make a limit for 20 MB of one? I have tried this solution: https://stackoverflow.com/a/166269/2126 which updates the constraint at runtime. However, this updates it for each session and each controller. So, if one user uploads a file for the first form, another using the load in the second form must have a restriction of the first ...
Any help? thanks
java spring-mvc upload
Goyo
source share