title: Unexpected token in JSON at position 0 - Angular2 - Spring API
body: <p>My REST API which has been written in SpringBoot has following method for the purpose of uploading a photo. </p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST, value = "/save-photo")
  public ResponseEntity&lt;?&gt; uploadPhoto(@RequestPart("file") MultipartFile file){
  
      if (file.isEmpty()) {
          System.out.println("Attached file is empty");
          ErrorResponse errorResponse = new ErrorResponse();
          errorResponse.setMessage("Attached file is empty");
          return new ResponseEntity&lt;ErrorResponse&gt;(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
      }
      String returnPath = null;
      try {
          byte[] bytes = file.getBytes();
          String saveDate = new SimpleDateFormat("yyMMddHHmmssSSS").format(new Date());
          Path path = Paths.get(UPLOAD_FOLDER + saveDate + "___"  + file.getOriginalFilename());
          Files.write(path, bytes); 
          returnPath = String.valueOf(path);
      } catch (IOException e) {
          //e.printStackTrace();
          ErrorResponse errorResponse = new ErrorResponse();
          errorResponse.setMessage(e.getMessage());
          return new ResponseEntity&lt;ErrorResponse&gt; (errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
      }
      System.out.println("Before returning, return path = "+returnPath);
      return new ResponseEntity&lt;String&gt;(returnPath, HttpStatus.OK);
  }
  </code></pre>
  
  <p>Following is the code I have written to call the above method.</p>
  
  <pre><code>savePhoto(photoToSave: File) {
  
      let formData: FormData = new FormData();
      formData.append("file", photoToSave);
  
      let savedPath = this._http
          .post(this._endpointUrl + "/save-photo", formData)
          .map(
          res =&gt; {
              return res.json();
          }
          )
          .catch(handleError);
  
      return savedPath;
  
  }
  </code></pre>
  
  <p>File uploading process is fine. But Angular2 gives me the following error.</p>
  
  <blockquote>
    <p>Unexpected token F in JSON at position 0</p>
  </blockquote>
  
  <p>Note that the F is the starting letter of the path the server returns. </p>
  
  <p>Why this happens? I think the server response is not a JSON. But why? Usually RestControllers return JSON. All other controller methods in my server works fine. 
  How to resolve this?</p>
  
  <p>Response Captured from Browser console</p>
  
  <p>Header:</p>
  
  <pre><code>Access-Control-Allow-Credentials:true
  Access-Control-Allow-Origin:http://localhost:3000
  Content-Length:88
  Content-Type:application/json;charset=UTF-8
  Date:Fri, 26 May 2017 04:33:05 GMT
  Vary:Origin
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>F:\Work\Images\170526100305388___2.jpg
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Screen shots from the brwoser
  <a href="https://i.stack.imgur.com/mUZxI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mUZxI.png" alt="enter image description here"></a></p>
  
  <p>Response:</p>
  
  <p><a href="https://i.stack.imgur.com/mt49U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mt49U.png" alt="enter image description here"></a></p>