title: upload file springboot Required request part 'file' is not present
body: <p>I want to add an upload function to my spring boot application; 
  this is my upload Rest Controller </p>
  
  <pre><code>package org.sid.web;
  
  import java.io.BufferedOutputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.servlet.ServletContext;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpEntity;
  import org.springframework.http.HttpHeaders;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.MediaType;
  import org.springframework.http.ResponseEntity;
  import org.springframework.stereotype.Controller;
  import org.springframework.util.LinkedMultiValueMap;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.bind.annotation.RestController;
  import org.springframework.web.client.RestTemplate;
  import org.springframework.web.multipart.MultipartFile;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  import org.springframework.core.env.Environment;
  import org.springframework.core.io.ClassPathResource;
  import org.springframework.core.io.FileSystemResource;
  import org.sid.entities.FileInfo;
  
  @RestController
  public class UploadController {
    @Autowired
    ServletContext context;
  
    @RequestMapping(value = "/fileupload/file", headers = ("content-type=multipart/*"), method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResponseEntity&lt;FileInfo&gt; upload(@RequestParam("file") MultipartFile inputFile) {
      FileInfo fileInfo = new FileInfo();
      HttpHeaders headers = new HttpHeaders();
      if (!inputFile.isEmpty()) {
        try {
          String originalFilename = inputFile.getOriginalFilename();
          File destinationFile = new File(
              context.getRealPath("C:/Users/kamel/workspace/credit_app/uploaded") + File.separator + originalFilename);
          inputFile.transferTo(destinationFile);
          fileInfo.setFileName(destinationFile.getPath());
          fileInfo.setFileSize(inputFile.getSize());
          headers.add("File Uploaded Successfully - ", originalFilename);
          return new ResponseEntity&lt;FileInfo&gt;(fileInfo, headers, HttpStatus.OK);
        } catch (Exception e) {
          return new ResponseEntity&lt;FileInfo&gt;(HttpStatus.BAD_REQUEST);
        }
      } else {
        return new ResponseEntity&lt;FileInfo&gt;(HttpStatus.BAD_REQUEST);
      }
    }
  }
  </code></pre>
  
  <p>but when testing this in postman with inserting <a href="http://localhost:8082/fileupload/file" rel="noreferrer">http://localhost:8082/fileupload/file</a> and adding a file to the body 
  i got this error:   "exception": <code>org.springframework.web.multipart.support.MissingServletRequestPartException",
    "message": "Required request part 'file' is not present</code>,</p>