马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
介绍: A项目调用B项目接口并提供与B雷同接口
- @PostMapping
- @ApiOperation("add")
- public AjaxResult add(@RequestParam(value = "file") MultipartFile file, RemoteSense remoteSense) throws IOException {
- if (file == null || file.isEmpty()) {
- return AjaxResult.error("文件不能为空");
- }
- // 将 RemoteSense 对象转换为 Map 以便传递参数
- Map<String, Object> remoteSenseParams = BeanUtil.beanToMap(remoteSense, false, true);
- // 将 InputStream 封装为 Hutool 的 Resource
- Resource fileResource = new InputStreamResource(file.getInputStream(), file.getOriginalFilename());
- // 使用 Hutool 的 form 方法传递 Resource
- HttpResponse response = HttpRequest.post(REMOTE_SENSE_BASE_URL)
- .form("file", fileResource) // 直接传递 InputStreamResource 代替 File
- .form(remoteSenseParams) // 添加其他参数
- .execute();
- return JSON.parseObject(response.body(), AjaxResult.class);
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |