I’m upgrading my project from Spring 5.x to Spring 6.1.13 due to vulnerabilities in the older version.
However, during the upgrade, I noticed that the CommonsMultipartResolver
class from the org.springframework.web.multipart.commons
package has been removed from the spring-web.jar.
I found that the StandardServletMultipartResolver
class can be used as an alternative. However, I’m having trouble finding a replacement for the setMaxUploadSize(int)
and setDefaultEncoding(String)
methods, which were available in CommonsMultipartResolver
class, in the newer Spring 6.x version.
What should I do to handle this?
MADHURA PRASAD S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
According to Upgrading to Spring Framework 6.x as you’ve mentioned you have to use StandardServletMultipartResolver
but there is no way to set custom parameters.
Without any piece of code I can’t help you with an implementation but I could give you steps to follow.
What can you do ?
Just use default StandardServletMultipartResolver
without any additional configuration in this case spring will handle all configuration stuff, because all Servlet 5.0+ containers have built-in multipart support.
If you have use-cases where default values should be changed like maxUploadSize
of defaultEncoding
Use commons-fileupload
for jakarta.servlet
to have more details check this post commons-fileupload-and-jakarta-servlet and jetty-11-and-commons-fileupload.
Some other examples how you can handle it you will be able to find out reading comments related to this GitHub issue 29562