title: Uploading large files won't work in Tomcat
body: <p>I have a web application (Java / spring / hibernate) running in production on Tomcat7.</p>
  
  <p>I manage to upload files easily but now I need to be able to upload large files (I have a 36MB file to upload).</p>
  
  <p>Whenever I upload a large file I get 405 (Method Not Allowed) error</p>
  
  <p>The log show the following lines:</p>
  
  <pre><code>415157         2014-11-19 14:53:03,662 INFO [http-bio-443-exec-52] com.eloan.controller.api.UploadFileController WFPIRSUM.PRN uploaded! 
  428860         2014-11-19 14:53:17,365 WARN [http-bio-443-exec-52] org.springframework.web.servlet.PageNotFound Request method 'POST' not supported
  </code></pre>
  
  <p>The first line is from my code:</p>
  
  <pre><code>@RequestMapping(value = "/boi", method = RequestMethod.POST)
  @CheckSessionAnnotation(type = 99)
  @ResponseBody
  public Integer upload(MultipartHttpServletRequest request, HttpServletResponse response) throws E000EloanException {
      LenderDetails anss = usService.getCurrentUserLenderDetails();
      int totalLines = 0;
  
      if (null == anss) { // user not in session...
          throw new E666UserNotInSessionException("User not in Session");
      }
  
      // this is a fix for IE
      response.setContentType("text/html");
  
      // 1. build an iterator
      Iterator&lt;String&gt; itr = request.getFileNames();
      MultipartFile mpf = null;
  
      String doc_type = request.getParameter("doc_type");
      List&lt;String&gt; lines = new ArrayList&lt;String&gt;();
      // 2. get each file
      while (itr.hasNext()) {
  
          mpf = request.getFile(itr.next());
          LOG.info(mpf.getOriginalFilename() + " uploaded! ");
  
          try {
  
              BufferedReader reader = new BufferedReader(new InputStreamReader(mpf.getInputStream(), "Windows-1255"));
              String line = null;
              while ((line = reader.readLine()) != null) {
                  // LOG.info("read [" + line + "] doc_tyep [" + doc_type +
                  // "]");
                  lines.add(line);
                  // boiService.addBankOfIsraelEntry(line, doc_type);
                  totalLines++;
              }
  
          } catch (IOException e) {
              LOG.error("File upload error for ", e);
              throw new E107IllegalCallException("File Upload Error");
          }
  
      } ...
  </code></pre>
  
  <p>In order to support large files I've tried the following (set the max size in the multipart config as annotation and as function call:</p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  @EnableAsync
  @MultipartConfig(maxFileSize = 52428800)
  public class EloanApiWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
  /**
   * Supports FileUploads.
   */
  @Bean
  public MultipartResolver multipartResolver() {
      CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
      multipartResolver.setMaxUploadSize(52428800);
      return multipartResolver;
  }
  }
  </code></pre>
  
  <p>I've tried to set it in the server.xml connector:</p>
  
  <pre><code>&lt;Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
             maxThreads="150" scheme="https" secure="true" maxPostSize="52428800"
             keystoreFile="/var/lib/tomcat7/conf/keystore" keystorePass="Lj6xK8sk"
             clientAuth="false" sslProtocol="TLS" server="eLoanSecureBSD-Server" /&gt;
  </code></pre>
  
  <p>And in the web.xml file:</p>
  
  <pre><code>&lt;multipart-config&gt;
          &lt;max-file-size&gt;52428800&lt;/max-file-size&gt;
          &lt;max-request-size&gt;52428800&lt;/max-request-size&gt;
      &lt;file-size-threshold&gt;52428800&lt;/file-size-threshold&gt;
      &lt;/multipart-config&gt;
  </code></pre>
  
  <p>It won't work!</p>
  
  <p>BTW - when I run in eclipse (using JETTY server from a main) it runs perfectly without any issues...</p>
  
  <p>Thank guys!</p>