赞
踩
// 传递附件给XX系统 public void uploadMaterial(String token,byte[] body) throws IOException { token = "eyJhbMGFlMjFmOTczZjAwYWVhMDM5IiwidWlkIjoiMSJ9.e629165c7430af605853cb1c5d7d66b5565cbb7124c0bff1f1c65d762e3a3671"; String url = "http://127.0.0.1/v5/meeting/user/uploadstmp"; HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.valueOf(MediaType.MULTIPART_FORM_DATA_VALUE)); httpHeaders.add("token",token); //httpHeaders.add("Content-Type", "text/html;charset=utf-8"); RestTemplate restTemplate = new RestTemplate(); // 由于我们传递的是byte[]数组,所以这里用的是ByteArrayResource对象 /*ByteArrayResource byteArrayResource = new ByteArrayResource(body) { @Override public String getFilename() { return "file"; } };*/ ByteArrayResource byteArrayResource = new ByteArrayResource(body) { @Override public String getFilename() { //重写文件名称 return "aa.docx"; } }; httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA); MultiValueMap multiValueMap = new LinkedMultiValueMap<>(); multiValueMap.add("m_id", "24"); multiValueMap.add("u_id", "101119"); multiValueMap.add("file", byteArrayResource); ResponseEntity<String> result = null; HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multiValueMap, httpHeaders); result = restTemplate.exchange(url, HttpMethod.POST, httpEntity,String.class); //responseEntity.getBody(); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。