java发送文件POST方式MutipartFile转FifleSystemResource
用restTemplate
public FifleSystemResource(MutipartFile file) {
//创建请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.add(“XXX”, X);
headers.add(“XXX”,X);
headers.add(“time_stamp”,timeStamp);
MultiValueMap<String, FileSystemResource> params = new LinkedMultiValueMap<>();
FileUtils.writeByteArrayToFile(new File(file.getOriginalFilename()), file.getBytes());
FileSystemResource fileResource = new FileSystemResource(new File(file.getOriginalFilename()));
params.add("file", fileResource);
HttpEntity<MultiValueMap<String, FileSystemResource>> formEntity = new HttpEntity<>(params, headers);
log.info(CHECK_IMG_RESOURCE_NAME+":{} {}",url,formEntity);
ResponseEntity<JSONObject> response = restTemplate.postForEntity(url,formEntity,JSONObject.class);
log.info(CHECK_IMG_RESOURCE_NAME+"完成:{}",response);
return response;
}