title: Sending a MultipartFile as a Request Param to REST server using Angular2
body: <p>I need to upload a photo to the server which has been written using Spring Boot. For the front end which sends the request I use Angular2.</p>
  
  <p>This is my API which accepts the HTTP request. It works fine. (I tested it using Postman)</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST, value = "/tender/save-new/save-photo")
  public ResponseEntity&lt;?&gt; uploadPhoto(@RequestParam("file") MultipartFile file){
  
      if (file.isEmpty()) {
          ErrorResponse errorResponse = new ErrorResponse();
          errorResponse.setMessage("DEBUG: Attached file is empty");
          return new ResponseEntity&lt;ErrorResponse&gt;(errorResponse, HttpStatus.NOT_FOUND);
      }
      String returnPath = null;
      try {
          // upload stuff
      } catch (IOException e) {
          ErrorResponse errorResponse = new ErrorResponse();
          errorResponse.setMessage(e.getMessage());
          return new ResponseEntity&lt;ErrorResponse&gt; (errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
      }
  
      return new ResponseEntity&lt;String&gt;(returnPath, HttpStatus.OK);
  }
  </code></pre>
  
  <p>I am not sure how should I write the code in Angular2 to call the server. 
  Following is what I have come up with.</p>
  
  <pre><code> savePhoto(photoToSave: File) {
  
      let formData: FormData = new FormData();
      formData.append('file', photoToSave);
  
      let savedPath = this._http
          .post(this._endpointUrl + "tender/save-new/save-photo", formData)
          .map(
          res =&gt; {
              return res.json();
          }
          )
          .catch(handleError);
  
      return savedPath;
  }
  </code></pre>
  
  <p>As you can see, I append the <code>'file'</code> parameter to the form data before sending it. Server method accepts the <code>RequestParam</code> as <code>'file'</code>.</p>
  
  <p>But, in the server log, I get following error. </p>
  
  <blockquote>
    <p>org.springframework.web.multipart.MultipartException: Current request
    is not a multipart request    at
    org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:190)</p>
  </blockquote>
  
  <p>Note that I haven't declared a <code>CommonsMultipartResolver</code> bean since SprinBoot implicitly handles it. (I have heard this. Please correct if I am wrong.)</p>
  
  <p>I think that the error comes up because of a missing value in the request. What Spring is saying by <code>handleMissingValue</code>? What am I missing? </p>