简体   繁体   中英

Spring boot, empty multipart files

A request comes from the service, multipart/form-data http://joxi.ru/D2P5g6Eiq0NjjA

Controller method:

@RequestMapping(value = "/*", params = "create", method = RequestMethod.POST)
ResponseEntity<?> createPost(
        @RequestParam MultiValueMap<String, String> allParameters,
        @RequestParam(value="data", required=false) CommonsMultipartFile locationMapFileData,
        MultipartHttpServletRequest mrequest,
        HttpServletRequestWrapper request,
        @RequestBody MultipartFile[] submissions
) {
   return sapService.createPost(allParameters);
}

Debug: http://joxi.ru/52a7XJySEMwG5r

what am I doing wrong? how can i get the contents of files?

ps sorry by translate english

At first, the files are not the request body, they are part of it and there is no built-in HttpMessageConverter that can convert the request to an array of MultipartFile .

Thus, you need to specify the name of the part (there may be several parts with the same name), for example, we expect a few files under the "files" part:

@RequestMapping(value = "/*", method = RequestMethod.POST)
ResponseEntity<?> createPost(@RequestParam("files") MultipartFile[] uploadFiles)   
{
  ...iterate over the uploadFiles and perform the necessary processing for each file
  return new ResponseEntity<>(HttpStatus.OK);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM