使用springcloud Fegin上传文件报错Could not write request: no suitable HttpMessageConverter found for request

在SpringCloud微服务中使用Feign调用文件上传服务时遇到'Could not write request: no suitable HttpMessageConverter found for request'的错误。问题在于缺少合适的HttpMessageConverter。解决方案包括在pom.xml中添加相关依赖,创建配置类进行设置,并通过Feign正确调用上传文件接口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

一、问题简介

在springcloud微服务中,需要用到feign去调用文件上传的服务,如通过fastdfs文件服务器上传文件:

1、fegin的接口配置(服务降级代码:略~)

@FeignClient(value = "XXXXXXXX-XXXXX-PROVIDER", fallbackFactory = XxxxxxClientFallbackFactory.class)
public interface XxxxxxClientService {
    /**
     * 保存图片
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/xxxxx/xxxxx/saveFile", method = RequestMethod.POST, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result saveFile(@RequestPart("file") MultipartFile file) throws Exception;
}

 2、服务入口代码:

    /**
     * 保存文件
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/xxxxx/xxxxx/saveFile", method = RequestMethod.POST, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result saveFile(@RequestPart("file") MultipartFile file) throws Exception {
        try {
            return xxxxxxClientService.saveFile(file);//fegin接口服务调用
        } catch (Exception e) {
            log.error("~~~~", e);
        }
        return Result.error();

    }

3、文件上传服务(单独访问该服务,上传文件成功~) 

@RequestMapping(value = "/xxxxxx/saveFile", method = RequestMethod.POST)
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值