I had commons-fileupload before spring migration to handle multipart-form data. After spring 6.x migration I am now using StandardServletMultipartResolver by creating bean of it in servlet-context like below
<bean id="multipartResolver"
class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
</bean>
Also I have dispatcher servlet configuration in my web.xml containing <multipart-config>
element as below:
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<multipart-config>
<location>test</location>
<max-file-size>1000000</max-file-size>
<max-request-size>1000000</max-request-size>
<file-size-threshold>1000000</file-size-threshold>
</multipart-config>
</servlet>
My multipart API defined inside controller is being processed successfully.
However this multipart configurations in dispatcher servlet are not picked up. Tomcat container is picking default configurations while performing request.getParts()
.
Below is tomcat's internal request class's code which picks default:
Context context = getContext();
MultipartConfigElement mce = getWrapper().getMultipartConfigElement();
I read that @multipartConfig annotation is for servlets and does not work for controllers. Also I don't have spring-boot in my project. Its simple spring-web application.
How to configure the filesize and other values for controllers?