title: Multipart post request from Angular To Spring
body: <p>I am here trying to post some data from Angular App to spring boot backend, and unfortunately, I am stuck with an incomprehensible bug for a day,</p>
  <p>This is my API</p>
  <pre><code>@PostMapping(&quot;/add&quot;, consumes = [&quot;multipart/form-data&quot;])
  fun addTeam(
      @RequestPart(name = &quot;file&quot;) file: MultipartFile,
      @RequestPart(name = &quot;body&quot;) team: Team
  ): ResponseEntity&lt;*&gt; {
      val imgUrl = filesStorageService.storeFile(file)
  
      val fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath()
          .path(&quot;/storage/downloadFile/&quot;)
          .path(imgUrl)
          .toUriString()
  
  
      val list = teamService.addTeam(team, fileDownloadUri)
      return ResponseEntity(list, list.status)
  }
  </code></pre>
  <p>and here's the Angular API call</p>
  <pre><code>addTeam(team: Team, coverFile: File): Observable&lt;boolean&gt; {
  return new Observable&lt;boolean&gt;(subscriber =&gt; {
    let formDate = new FormData();
    formDate.append('file', coverFile);
    formDate.append('body', JSON.stringify(team));
    this
      .client
      .post&lt;ResponseWrapper&lt;Boolean&gt;&gt;(environment.BASE_URL + this.ADD_TEAM, formDate, {
        headers: {'Content-Type': 'multipart/form-data'},
       })
  ......
  </code></pre>
  <p>so here I got an exception saying</p>
  <pre><code>org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
  </code></pre>
  <p>so I found some solutions tell to set the angular content type to <code>undefined</code> but this also did not work
  then I removed the content type from the angular call</p>
  <p>but this gives me another error</p>
  <pre><code>2020-12-12 19:12:41.298  WARN 16892 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported]
  </code></pre>
  <p>so I made the spring app accepts <code>application/octet-stream</code> but it results ,</p>
  <pre><code>2020-12-12 19:14:39.775  WARN 16796 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;boundary=----WebKitFormBoundarykunWjFPmOyVdc8vn' not supported]
  </code></pre>
  <p>so can anyone help me through this?</p>
  <p>Also, I tried this API using postman and it's working when I put content type to <code>multipart/form-data</code></p>