title: Spring file upload content type validation, always octet-stream?
body: <p>I'm trying to implement pdf file uploading in my Restful Spring Boot application.</p>
  
  <p>I have the following method;</p>
  
  <pre><code>@RequestMapping(value = FILE_URL, method = RequestMethod.POST)
  public ResponseDTO submitPDF(
          @ModelAttribute("file") FileDTO file) {
  
      MediaType mediaType = MediaType.parseMediaType(file.getFile().getContentType());
  
      System.out.println(file.getFile().getContentType());
      System.out.println(mediaType);
      System.out.println(mediaType.getType());
  
      if(!"application/pdf".equals(mediaType.getType())) {
          throw new IllegalArgumentException("Incorrect file type, PDF required.");
      }
  
      ... more code here ...
  }
  </code></pre>
  
  <p>FileDTO is just a wrapper around MultipartFile.</p>
  
  <p>I'm then using Postman to POST the request with <code>form-data</code> body <code>'file'=&lt;filename.pdf&gt;</code></p>
  
  <p>The content type in the printlns above is ALWAYS octet-stream. No matter what type of file I send in (png, pdf, etc) its always octet stream. If I specifically set <code>application/pdf</code> as Content-Type header in Postman the MultipartFile within FileDTO ends up as null.</p>
  
  <p>Question is, is there something wrong with my Spring Controller method, or is the request just not being built correctly by Postman?</p>
  
  <p>If Postman can't get the Content-Type right, can I expect actual client apps to properly set content type to pdf?</p>