title: Getting 415 Unsupported Media Type while trying to upload a file in Spring Rest api
body: <p>I have made a service which accepts a file and tries to store in local file system
  but when i try to make a request to this service with a html file </p>
  
  <p>I have googled for this error but many told that error is due to misconfig at server so please tell any changes on my server</p>
  
  <p>my server java code:</p>
  
  <pre><code>@RequestMapping(value = "/upload",headers = "Content-Type=multipart/form-data", method = RequestMethod.POST)
      @ResponseBody
      public String upload(@RequestBody MultipartFile file)
      {
          name = "/path";
  
          if (!file.isEmpty()) {
              try {
                  byte[] bytes = file.getBytes();
                  BufferedOutputStream stream =
                          new BufferedOutputStream(new FileOutputStream(new File(name)));
                  stream.write(bytes);
                  stream.close();
                  System.out.println(file);
               //s   return "You successfully uploaded " + name + "!";
              } catch (Exception e) {
                  return "You failed to upload " + name + " =&gt; " + e.getMessage();
              }
          } else {
              return "You failed to upload " + name + " because the file was empty.";
          }
          }
          return "";
      }
  </code></pre>
  
  <p>my html file:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;form method="POST" enctype="multipart/form-data"
          action="http://localhost:8080/upload"&gt;
          File to upload: &lt;input type="file" class = "file" name="file"&gt;&lt;br /&gt; &lt;br /&gt; &lt;input type="submit"
              value="Upload"&gt; Press here to upload the file!
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>