title: Payload too large error (413) when uploading using JS Fetch API. Works fine via Postman
body: <p>I have a multipart upload API that works flawlessly when I upload a file via Postman. However, when I upload via the same API but using Fetch API, I get 413 error.</p>
  <p>I tried the solution given <a href="https://stackoverflow.com/questions/57897803/spring-boot-upload-multipart-413-request-entity-too-large">here</a> but it did not work.</p>
  <p>My JS code is as follows -</p>
  <pre><code>async function uploadAudio(formElements) {
  
      const formData = new FormData();
      const file = fileUploadField.files[0];
      formData.append(&quot;file&quot;, file);
  
      console.log(&quot;Name: &quot; + file.name); // Prints the correct file name
      console.log(&quot;Size: &quot; + file.size); // Prints the correct size (which is &lt; than what is set server side)
  
      const options = {
            method: 'POST',
            body: formData,
            headers: {
              'Content-Type': 'multipart/form-data',
              'Accept': 'application/json',
              'Authorization': 'Bearer ' + authTokenArr[0]
            }
          };
  
      const response = await fetch(base_url + &quot;/audio/file&quot;, options);
      const data = await response.json();
  
      if (response.ok) {
          handleSuccess(data);
      } else {
          handleFail(data);
      }
  } 
  </code></pre>
  <p><code>application.properties</code> file -</p>
  <pre><code># max file size
  spring.servlet.multipart.max-file-size=10MB
  # max request size
  spring.servlet.multipart.max-request-size=10MB 
  </code></pre>
  <p>REST controller -</p>
  <pre><code>@PostMapping(&quot;file&quot;, produces = [ProduceTypes.JSON])
      fun uploadAudio(@RequestParam(&quot;file&quot;) file: MultipartFile,
                        @RequestHeader (name=&quot;Authorization&quot;) token: String): ResponseEntity&lt;MutableMap&lt;String, Any&gt;&gt; {
  
          val user: User = userService.getUserDetailsByToken(token)
  
          val body: MutableMap&lt;String, Any&gt; = LinkedHashMap()
          body[&quot;status&quot;] = ApiStatus.UPLOADED
          body[&quot;fileId&quot;] = podcastFileService.uploadFileToB2(user, file)
  
          return ResponseEntity(body, HttpStatus.CREATED)
      }
  </code></pre>
  <p>Here is my server side log -</p>
  <pre><code>2020-09-03 18:56:02.288 DEBUG 40716 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet        : POST &quot;/audio/file&quot;, parameters={}
  2020-09-03 18:56:02.293 DEBUG 40716 --- [nio-8080-exec-7] .m.m.a.ExceptionHandlerExceptionResolver : Using @ExceptionHandler com.krtkush.audiotime.globalexceptions.GlobalExceptionHandler#handleMultipartException(MultipartException)
  2020-09-03 18:56:02.356 DEBUG 40716 --- [nio-8080-exec-7] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
  2020-09-03 18:56:02.357 DEBUG 40716 --- [nio-8080-exec-7] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [{timestamp=2020-09-03T18:56:02.297867, message=Maximum file size acceptable is 10MB}]
  2020-09-03 18:56:02.364 DEBUG 40716 --- [nio-8080-exec-7] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found]
  2020-09-03 18:56:02.364 DEBUG 40716 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet        : Completed 413 PAYLOAD_TOO_LARGE
  </code></pre>
  <p>Why would there be a size problem when the API is working fine via Postman and even when uploaded using <code>mustache</code> template with a non-REST controller.</p>