首先在远程机器上写好服务:
@RequestMapping(value = "/upload",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<ReturnMsg<String>> uploadFiles(
@RequestParam(value = "file", required = false) MultipartFile file)
throws YMLibWebApplicationException {
return fullTextLibraryService.uploadFiles(file);
};
本地调用如下:
String path = "F:\\wordToPdf\\" + type + "\\";
File file = new File(path);
FileSystemResource resource = new FileSystemResource(file);
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("file", resource);
//远程服务器启用了aouth2协议
param.add("access_token", access_token);
ReturnMsg<String> returnmsg = restTemplate.postForObject(uploadPdf_addr, param, ReturnMsg.class);
经测试 上传成功。