feign遠端調用MultipartFile檔案上傳格式問題
1. Current request is not a multipart request
feign遠端調用檔案上傳時常用的接口寫法會報出Current request is not a multipart request錯誤
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIyVGduV2YfNWawNyZuBnL5ETMwQzMxETM3IDOwAjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
解決方法需要在post請求中添加consumes = MediaType.MULTIPART_FORM_DATA_VALUE
2. the request was rejected because no multipart boundary was found
上述問題解決後又報出the request was rejected because no multipart boundary was found錯誤
解決方法修改feign接口的接收配置,設定為 @RequestPart
用戶端擷取檔案
@PostMapping("/upload/image")
public R uploadImage(@RequestParam("multipartFile") MultipartFile multipartFile){
return imageFeignService.policy(multipartFile);
}
feign接口,注意此處feign接口為 @RequestPart而不是用戶端中的 @RequestParam
@PostMapping(value = "/oss/policy", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
R policy(@RequestPart("multipartFile") MultipartFile multipartFile);
oss檔案上傳見
https://blog.csdn.net/weixin_43959260/article/details/108147578