feign.codec.EncodeException: Error converting request body


前言

最近在做上传文件时,需要调 feign 接口去上传,出了点小差错。feign.codec.EncodeException: Error converting request body。需要在feign接口上加类型以及@RequestPart。


提示:以下是本篇文章正文内容,下面案例可供参考

一、错误回顾

1.详细信息

feign.codec.EncodeException: Error converting request body
	at org.springframework.cloud.openfeign.support.SpringEncoder.encodeWithMessageConverter(SpringEncoder.java:141) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.openfeign.support.SpringEncoder.encode(SpringEncoder.java:119) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.openfeign.support.PageableSpringEncoder.encode(PageableSpringEncoder.java:101) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at feign.ReflectiveFeign$BuildFormEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:358) ~[feign-core-10.12.jar:na]
	at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:232) ~[feign-core-10.12.jar:na]
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:84) ~[feign-core-10.12.jar:na]
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100) ~[feign-core-10.12.jar:na]
	at com.sun.proxy.$Proxy216.fileUpload(Unknown Source) ~[na:na]
	at com.sty.resource.web.service.impl.CabinetServiceImpl.importExcel(CabinetServiceImpl.java:120) [classes/:na]

二、解决方案

1.feign代码详情

需要在接口上加类型:
consumes = MediaType.MULTIPART_FORM_DATA_VALUE 以及 @RequestPart(value = “file”)

@PostMapping(value = "/uploadfile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
R fileUpload(@RequestPart(value = "file") MultipartFile uploadFile) throws Exception;

2.调用代码详情

需要加上:@RequestPart(value = “file”) 与 feign 接口加的一致

@PostMapping(value = "/uploadfile")
public R fileUpload(@RequestPart(value = "file") MultipartFile uploadFile) throws Exception {...}

总结

别人对你好,那是你的造化,懂得感恩,才有好运气;别人对你不好,那也是你的造化,懂得宽容,才有好心境。

在这里插入图片描述

  • 14
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值