1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| String url = "接收文件的地址"; HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
byte[] bytes = file.getBytes(); File fileToSave = new File(file.getOriginalFilename());
FileCopyUtils.copy(bytes, fileToSave);
FileSystemResource resource = new FileSystemResource(fileToSave); MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("file", resource); HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(param, headers);
HttpEntity<Result> responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
responseEntity.getBody();
|