title: Grails 2.4 limit/max upload size
body: <p>With regards to <a href="https://brainflush.wordpress.com/2008/12/04/how-to-gracefully-recover-from-file-upload-errors-in-grails/" rel="nofollow">https://brainflush.wordpress.com/2008/12/04/how-to-gracefully-recover-from-file-upload-errors-in-grails/</a> I can't get it working on Grails 2.4.</p>
  
  <p>I've added this to my Grails app:</p>
  
  <p>resources.groovy</p>
  
  <pre><code>beans = {
      multipartResolver(CustomMultipartResolver) {
          maxUploadSize = 2000000
      }
  }
  </code></pre>
  
  <p>added to BootStrap.groovy</p>
  
  <pre><code>public class CustomMultipartResolver extends CommonsMultipartResolver {
  
     static final String FILE_SIZE_EXCEEDED_ERROR = "fileSizeExceeded"
  
     public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) {
  
        try {
           return super.resolveMultipart(request)
        } catch (MaxUploadSizeExceededException e) {
           request.setAttribute(FILE_SIZE_EXCEEDED_ERROR, true)
           return new DefaultMultipartHttpServletRequest(request, new LinkedMultiValueMap(), [:])
        } catch (SizeLimitExceededException e) {
           request.setAttribute(FILE_SIZE_EXCEEDED_ERROR, true)
           return new DefaultMultipartHttpServletRequest(request, new LinkedMultiValueMap(), [:])
        }
     }
  }
  </code></pre>
  
  <p>In controller:</p>
  
  <pre><code>if (request.getAttribute(CustomMultipartResolver.FILE_SIZE_EXCEEDED_ERROR)) {
     ModActionFile.errors.reject("MyDomain.fileSizeTooLarge")
     redirect(controller:'MyDomain', action:'create',params:params)
  } else {...
  </code></pre>
  
  <p>I get this error</p>
  
  <pre><code>Error |
  2015-03-17 16:08:57,794 [http-bio-8080-exec-8] ERROR [/tool].[default]  - Servlet.service() for servlet [default] in context with path [/tool] threw exception
  Message: Could not find matching constructor for: org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest(org.apache.catalina.connector.RequestFacade, org.springframework.util.LinkedMultiValueMap, java.util.LinkedHashMap)
      Line | Method
  -&gt;&gt;   43 | resolveMultipart in CustomMultipartResolver$$EP7CaraR
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  |   1145 | runWorker        in java.util.concurrent.ThreadPoolExecutor
  |    615 | run . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
  ^    745 | run              in java.lang.Thread
  </code></pre>