title: Why cant we get a file data from a RequestBody in java?
body: <p>I am trying to upload a file to a server so i am trying to use @RequestBody to get the data of the file, but i am getting 415 error code while trying to upload a file.</p>
  
  <p>So i have googled(got solution to upload a file) and got to know that i cant get file data from a request body. So i want to know why cant we access file data from request body as data will be sent in request body in HTTP requests, so i want to know how is the request happening in the case of uploading a file.</p>
  
  <p>My server code before:</p>
  
  <pre><code>@RequestMapping(value = "/upload",headers = "Content-Type=multipart/form-data", method = RequestMethod.POST)
  @ResponseBody
  public String upload(@RequestBody MultipartFile file)
  {
  }
  </code></pre>
  
  <p>Solution:</p>
  
  <pre><code>@RequestMapping(value = "/upload",headers = "Content-Type=multipart/form-data", method = RequestMethod.POST)
  @ResponseBody
  public String upload(MultipartHttpServletRequest request)
  {
  }
  </code></pre>