Home > Blockchain >  How to Solve in Swagger this problem https://stackoverflow.com/questions/16015548/how-to-send-multip
How to Solve in Swagger this problem https://stackoverflow.com/questions/16015548/how-to-send-multip

Time:10-19

I get this error when I add files in rest api.

2021-10-18 10:21:36.556  WARN 15128 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present]

Here is my rest api.

@ApiOperation(value = "Send file",
            notes = "This method accept a file")
    @PostMapping("/upload-file")
    public ResponseEntity<? extends Response> writeExcelledRowColumnIntoDatabase(@ApiParam(
            name = "file-name",
            type = ".xlsx",
            value = "Pass File Name",
            example = "file.xlsx",
            required = true) @RequestParam("file") MultipartFile pathFile) throws IOException {

        return this.userDetailService.acceptExcellFileAndInsertToDatabase(pathFile);

    }

I found something on the internet to do this, but I still get the same error. Is there any way I can solve this problem?

CodePudding user response:

You are using parameter "file" in the code @RequestParam("file")

and the swagger doc has file-name

Update the function param to this:

 @RequestParam("file-name") MultipartFile pathFile
  • Related