当我在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]
这是我的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);
}
我在网上找到了一些东西来做这个,但我仍然得到同样的错误。有什么办法可以解决这个问题吗?
您正在使用参数"file"代码@RequestParam("file")
和swagger文档有file-name
将函数参数更新为:
@RequestParam("file-name") MultipartFile pathFile