unsupported Media type 415 for file upload with Spring mvc restcontroller and angularjs
<p>When i am trying to hit the angularjs $http.post  which contains file upload details its giving me unsupported media type. I am using backend spring mvc rest controller. The following is the code snippet.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>    &lt;ul&gt;&lt;li&gt;&lt;h4&gt;Document Type&lt;/h4&gt;
    &lt;select name="docType"  ng-model="docType" name="docType"&gt;
    &lt;option value="Report1"&gt;Report1&lt;/option&gt; 
    &lt;option value="Report2"&gt;Report2&lt;/option&gt;
    &lt;/select&gt;
    &lt;input type="file" ng-model-instant id="fileToUpload" onchange="angular.element(this).scope().setFiles(this)" /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;h4&gt;Comments:&lt;/h4&gt;&lt;textarea&gt;&lt;/textarea&gt;&lt;/li&gt;
    &lt;li&gt;&lt;button  class="btn-panel-blue"  type="submit"&gt;Saves&lt;/button&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#/searchProjects"&gt;Cancel&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;</code></pre>
</div>
</div>
</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>angular.module('app')
.controller('prjCntrl', function ($scope,projectService, sharedService, $location, $log, $http, $state) {
 $scope.setFiles = function(element) {
     $scope.$apply(function(scope) {
         $scope.uploadedFile ;
         for (var i = 0; i &lt; element.files.length; i++) {
          $scope.uploadedFile=element.files[i];
          break;
         }
       });
     };
 $scope.updateProject = function updateProject()
 {
  var formData=new FormData();
  formData.append('docType',angular.toJson($scope.projectData.docType,true));
  formData.append("uploadFile",$scope.uploadedFile);
  var url=baseURL + '/updateProject.do';
  $http.post(url, formData, { transformRequest: angular.identity, headers: {'Content-Type': undefined} })
        .success(function(){alert("success");})
        .error(function(){ });
 };
}
);</code></pre>
</div>
</div>

and here is my java code.</p>

<pre><code>

    @RestController
    @MultipartConfig(fileSizeThreshold=1024*1024*10,  
    maxFileSize=1024*1024*50,          
    maxRequestSize=1024*1024*100)
    public class ProjectController {
    @RequestMapping(value="/updateProject.do",method = RequestMethod.POST,headers ="Accept=multipart/form-data", consumes={"multipart/form-data"}, produces={"text/plain;charset=UTF-8"})
        public @ResponseBody String updateProjectDetails(HttpServletRequest request, HttpServletResponse response,  @RequestBody ProjectForm command)
        {
            contractProjectsService.saveProject(command);
            return "success";
        }
    }

</code></pre>

<p>here is the header information from chrome headers/request and response data</p>

<pre><code>

    **General:**
    Request URL:http://localhost:9090/SpringMVCAngularJS/updateProject.do
    Request Method:POST
    Status Code:415 Unsupported Media Type
    Remote Address:[::1]:9090
    ***Response Headers:***
    view source
    Content-Language:en
    Content-Length:1048
    Content-Type:text/html;charset=utf-8
    Date:Wed, 03 Aug 2016 15:06:05 GMT
    Server:Apache-Coyote/1.1
    ***Request Headers:***
    view source
    Accept:application/json, text/plain, */*
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8
    Authorization:Basic YmVlcDpib29w
    Connection:keep-alive
    Content-Length:1011
    Content-Type:multipart/form-data; boundary=---- WebKitFormBoundaryagdf0LOX4AuXY6SI
    Cookie:JSESSIONID=96052E348C6E52F53A594A179E65DE6D
    Host:localhost:9090
    Origin:http://localhost:9090
    Referer:http://localhost:9090/SpringMVCAngularJS/index.html
    User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36

</code></pre>

<p>Please help me with the solution.</p>