Search code examples
springservletsmultipartresolver

Spring StandardServletMultipartResolver


I was wondering where is located the code that automatically create a temporary file when you send a multipart request using StandardServletMultipartResolver?

Can i disable that behavior? I want to decide how its going to be stored and where. I don't want spring to do it for me.

I'm considering creating my own resolver but I cant find information on how to disable spring default behavior.


Solution

  • To quote from API docs StandardServletMultipartResolver does not support temporary file configuration on resolver level rather it is to be done on servlet registration level -

    In order to use Servlet 3.0 based multipart parsing, you need to mark the affected servlet with a "multipart-config" section in web.xml, or with a MultipartConfigElement in programmatic servlet registration, or (in case of a custom servlet class) possibly with a MultipartConfig annotation on your servlet class.

    Configuration settings such as maximum sizes or storage locations need to be applied at that servlet registration level; Servlet 3.0 does not allow for them to be set at the MultipartResolver level.

    So either you can configure it on servlet or switch to CommonsMultipartResolver which has the support to set the temp directory out-of-the-box as it inherits it from CommonsFileUploadSupport.setUploadTempDir (see respective docs here and here)