title: "MultipartException: Current request is not a multipart request" when trying to upload file using javascript+ajax (works from postman)
body: <p>I am trying to create a web form that will allow uploading a single file from the browser to my own server.</p>
  <p>The backend API is spring boot based, the specific controller was tested with postman and worked well. Now when I am trying to make the same for my website using JavaScript and ajax I get the following error:</p>
  <ol>
  <li>Client side: Error 400 and</li>
  </ol>
  <blockquote>
  <pre><code>&gt; {&quot;status&quot;:&quot;NOT_FOUND&quot;,&quot;message&quot;:&quot;Current request is not a multipart
  &gt; request&quot;,&quot;timestamp&quot;:1604939158692}
  </code></pre>
  </blockquote>
  <ol start="2">
  <li>server-side:</li>
  </ol>
  <blockquote>
  <p>org.springframework.web.multipart.MultipartException: Current request
  is not a multipart request</p>
  </blockquote>
  <p>I have tried ~10 of the accepted solutions from other question on stackoverflow, but nothing helped.
  These are the relevant code parts.</p>
  <p>Spring controller:</p>
  <pre><code>    @PostMapping(&quot;/add_users_from_csv&quot;)
  public ResponseEntity&lt;String&gt; addUsersListFromCSVFile(@PathVariable String id,  @RequestParam(&quot;file&quot;) MultipartFile file, @RequestParam(&quot;club&quot;) String clubId, @RequestParam(&quot;notifyByEmail&quot;) boolean notifyByEmail, @RequestParam(&quot;notifyBySMS&quot;)  boolean notifyBySMS) throws UnauthorizedRequestException {
      businessService.securityCheckID(id);
      return clubService.addUsersListFromCSVFile(clubId, file, notifyByEmail, notifyBySMS);
  }
  </code></pre>
  <p>Client:</p>
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;form name=&quot;uploadForm&quot; id=&quot;fileUploadForm&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;
          &lt;input type=&quot;file&quot; id=&quot;file&quot; name=&quot;file&quot; value=&quot;Import&quot;&quot;&gt; 
          &lt;input type=&quot;submit&quot; value=&quot;Import&quot; id=&quot;Import&quot; /&gt;
      &lt;/form&gt;
      &lt;script type=&quot;text/javascript&quot;
          src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script&gt;
          $('form[name=&quot;uploadForm&quot;]').submit(function(event){
              event.preventDefault();
              var formData = new FormData($('#fileUploadForm')[0]);
              formData.append('file', $('input[type=file]')[0].files[0]); 
              formData.append(&quot;club&quot;, &quot;5cc5fd05569a720006169111&quot;);
              formData.append(&quot;notifyByEmail&quot;, &quot;true&quot;);
              formData.append(&quot;notifyBySMS&quot;, &quot;true&quot;);
                                  $.ajax({
                                      url: 'http://localhost:8090/business/5cc625ed3ba686000665f111/add_users_from_csv',
                                      data: formData,
                                      type: &quot;POST&quot;,
                                      contentType: false,
                                      processData: false,
                                      cache: false,
                                      &quot;headers&quot;: {
      &quot;Content-Type&quot;: &quot;application/json&quot;,
      &quot;Authorization&quot;: &quot;bearer 0278e739-fbe0-4e3d-9acf-57544b011111&quot;
    },
                                      success : function(response){
                                          alert(response); 
                                      },
                                      error: function(xhr,status,errorThrown) {
                                          alert(xhr.status); 
                                      }
                                  });
              return false;
          });
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Postman request (that works well with the same server):
  <a href="https://i.stack.imgur.com/tdUax.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tdUax.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/9LgJc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9LgJc.png" alt="enter image description here" /></a></p>
  <p>What makes the request from browser fail and how to fix it please ?</p>