spring restTemplate 上传文件流

要复写ByteArrayResource getFileName,否则报错

MultiValueMap bodyParams = new LinkedMultiValueMap<>();

org.springframework.core.io.Resource resource = new ByteArrayResource(byte[]){
    @Override
    public String getFilename() {
        return "sdfs";
    }
};

bodyParams.add("file", resource);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity> requestEntity = new HttpEntity<>(bodyParams, headers);
String returnVo = restTemplate.postForObject("http://file-yun.dev.rs.com/file/public/upload?token="+token, requestEntity, String.class);

你可能感兴趣的:(Java,Java,maven,web,restTemplate)