title: Spring MultipartException: The current request is not a multipart request
body: <p>I'm trying to upload a file with AngularJS and Spring  controller.
  The Angular controller looks like this:</p>
  
  <pre><code> $scope.uploadFile=function(){
   var formData=new FormData();
   formData.append("file",file.files[0]);
  
   $http.post('/content-files/upload /',  file.files[0], {
  
       transformRequest: function(data, headersGetterFunction) {
              return data; // do nothing! FormData is very good!
          },
       headers: {'Content-Type': undefined }
  
   })
   .success(function(){
       console.log('Post Succeded !');
   })
   .error(function(){
       console.log('Post Failed .');
   });
  }
  </code></pre>
  
  <p>I also try this: </p>
  
  <pre><code>var formData = new FormData();
  formData.append('file',file.files[0]);
  
  $http.post('/content-files/upload /',  formData, {         
    headers: { 'Content-Type': undefined },
    transformRequest: angular.identity
  })
  </code></pre>
  
  <p>and the Spring controller looks like this:</p>
  
  <pre><code>    @RequestMapping(value = "/content-files/upload/", method =   RequestMethod.POST  )           
  public @ResponseBody String handleFileUpload(  @RequestParam("file")      MultipartFile file) {
    System.out.println("BrandController.uploadMultipart()");
  
  String name=file.getName();
  if (!file.isEmpty()) {
      try {
          byte[] bytes = file.getBytes();
          BufferedOutputStream stream =
                        new BufferedOutputStream(new FileOutputStream(new File(name)));
          stream.write(bytes);
          stream.close();
          return "You successfully uploaded " + name + "!";
      } catch (Exception e) {
          return "You failed to upload " + name + " =&gt; " + e.getMessage();
      }
  } else {
      return "You failed to upload " + name + " because the file was empty.";
   }
   }
  </code></pre>
  
  <p>My html Page is :</p>
  
  <pre><code> &lt;form enctype="multipart/form-data"&gt;
     &lt;input id="file-0a" class="file" type="file" file-model="myFile" name="myFile" /&gt;
                   &lt;button ng-click="uploadFile()"&gt;upload me&lt;/button&gt;&lt;/form&gt;
  </code></pre>
  
  <p>i have 2 jars in web-inf/lib:commons-upload.jar and commons-io.jar
  I add this in  my spring configuration file:</p>
  
  <pre><code>&lt;bean id="multipartResolver"     class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
      &lt;property name="maxUploadSize" value="50000000"/&gt;
  &lt;/bean&gt; 
  </code></pre>
  
  <p>When I'm trying to upload a file, I get the error:</p>
  
  <pre><code>   org.springframework.web.multipart.MultipartException: The current request is   not a multipart request
  </code></pre>
  
  <p>When I'm trying to upload a file using MultipartHttpServletRequest in my spring function instead of Multipart i get this error:</p>
  
  <pre><code>    java.lang.IllegalStateException: Current request is not of type   [org.springframework.web.multipart.MultipartHttpServletRequest]: org.apache.catalina.connector.RequestFacade@196f5636
  </code></pre>
  
  <p>When i use HttpServletRequest request and i try to cast it i got a ClassCastException.
  Nothing change when i cancel enctype="multipart/form-data" from my form Tag</p>