feign传递文件、传递二进制流

传递文件

服务端

@RestController
public class DemoController {
  @PostMapping("/upload")
  @ApiOperation("上传文件")
  public void upload(@RequestParam("file") MultipartFile file) throws Exception {
		// todo
  }
}

客户端

  • 申明接口
    主要是加上 consumes = MediaType.MULTIPART_FORM_DATA_VALUE
@FeignClient
public interface IFeignService {
    @PostMapping(value = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Result upload(@RequestPart("file") MultipartFile file);
}

传递二进制流

服务端

@RestController
public class DemoController {
  @PostMapping("/upload")
  @ApiOperation("上传文件")
  public void upload(@RequestBody byte[] bytes, @RequestParam("suffix") String suffix) {
		// todo
  } 
}

客户端
申明接口
正常加上注解即可

@FeignClient
public interface IFeignRestService {
    @PostMapping(value = "/upload")
    Result upload(@RequestBody byte[] bytes, @RequestParam("suffix") String suffix);
}
posted @   fchhk  阅读(790)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 我与微信审核的“相爱相杀”看个人小程序副业
· DeepSeek “源神”启动!「GitHub 热点速览」
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示