话不多说,看代码

1,客户端调用代码

@PostMapping("/uploadAttachBase64")
public Result uploadAttachBase64(HttpServletRequest request, @RequestParam(value = "file",required = false) MultipartFile file,
@RequestParam(value = "orgId",required = false) String orgId) throws IOException {
// 校验登录
Map<String,Object> params = this.getLoginInfoMap(request);
if(StringUtils.isEmpty(orgId) || orgId.equals("")){
return Result.error("入参为空");
}
if(ObjectUtils.isEmpty(file) || file.getSize() <=0 ){
return Result.error("上传文件为空");
}
MultiValueMap valueMap = new LinkedMultiValueMap(1);
// 此处从multipartFile获取byte[],如果是上传本地文件可以使用io获取byte[]
ByteArrayResource is = new ByteArrayResource(file.getBytes()) {
@Override
public String getFilename() {
return file.getOriginalFilename();
}
};
valueMap.add("file", is);
valueMap.add("orgId",orgId);
String s = null;
RestTemplate restTemplate = new RestTemplate();
try {
s = restTemplate.postForObject(asiaInfoUrl + uploadAttachBase64, valueMap, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
return Result.success(JSONObject.parseObject(s));
}

2,服务端接口

 

参考:https://blog.csdn.net/qq_32513795/article/details/107958713