Spring Cloud OpenFeign MultipartException 上传文件异常
Spring Boot OpenFeign About 1,014 words错误信息
错误一:MultipartException
MultipartException: Current request is not a multipart request
错误二:FileUploadException
FileUploadException: the request was rejected because no multipart boundary was found
错误三:FileNotFoundException
FileNotFoundException: MultipartFile resource [file] cannot be resolved to absolute file path
解决方法
FeignClient
设置consumes
为multipart/form-data
。
注意:MultipartFile
需标注为@RequestPart
,而不是@RequestParam
。
@FeignClient(name = "file-upload", url = "${file-upload.url}")
public interface FileUploadFeignClient {
@PostMapping(value = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
UploadResponse fileUpload(@RequestPart("file") MultipartFile file);
}
Controller
@RequestMapping("/file")
@RestController
public class FileUploadController {
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public UploadResponse upload(@RequestPart("file") MultipartFile file) {
// logic
return UploadResponse.builder().build();
}
}
Views: 2,261 · Posted: 2022-10-26
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...