微服務(wù)feign 傳送文件
工作中有可能遇到使用feign中轉(zhuǎn)文件的情況這里記錄下使用方法
在常規(guī)引入openFeign的情況下加入以下依賴
<dependency> ? ?<groupId>io.github.openfeign.form</groupId> ? ?
<artifactId>feign-form</artifactId> ? ?
<version>3.8.0</version>
</dependency>
<dependency> ? ?
<groupId>io.github.openfeign.form</groupId> ? ?
<artifactId>feign-form-spring</artifactId> ? ?
<version>3.8.0</version>
</dependency>
2. 編寫文件傳輸接口
3. 需要注意:
? ?
?1. feignFormEncoder 方法的名字不要修改,我因?yàn)閱卧~拼錯(cuò)導(dǎo)致報(bào)錯(cuò),后面折騰很久。
? ?2. @RequestPart("file") MultipartFile multipartFile?這里一定要使用requestPart,不要使用requestParam?不然會(huì)出現(xiàn)報(bào)錯(cuò)?
4. 中轉(zhuǎn)接口:
特別注意:這里需要使用requestParam不然同樣會(huì)報(bào)錯(cuò)切記
標(biāo)簽: