I have a Spring MVC web with two different pages that have different forms to upload different files. One of them should have a limitation of 2MB, while the other should have a 50MB limitation.
Right now, I have this limitation in my app-config.xml:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes (2097152 B = 2 MB) -->
<property name="maxUploadSize" value="2097152 "/>
</bean>
And I could resolve the maxUploadSize exception in my main controller like that:
@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 controlls the 2MB limit. How could I make the limitation for the 20MB one? I've tried this solution: https://stackoverflow.com/a/11792952/1863783, which updates the limitation in runtime. However, this updates it for every session and every controller. So, if one user is uploading a file for the first form, another using uploading in the second form should have the limitation of the first one...
Any help? thanks