3 回答
TA贡献1868条经验 获得超4个赞
HttpHeaders headers = createHeaders(username, password);
headers.setContentType(MediaType.APPLICATION_PDF);
headers.set("X-Async-Scope", timelineEntryId);
InputStream inputStream = new FileSystemResource(new File(file.getPath())).getInputStream();
byte[] binaryData = IOUtils.toByteArray(inputStream);
HttpEntity<byte[]> requestEntity = new HttpEntity<>(binaryData, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange(baseUrl, HttpMethod.PUT, requestEntity, String.class);
TA贡献1815条经验 获得超10个赞
也许,您需要设置标题内容类型?
headers.set("Content-Type", "application/pdf")
如果没有帮助,您还应该设置标头 Content-Disposition:
headers.set("Content-Disposition", "attachment; filename="+fileName)
TA贡献1829条经验 获得超9个赞
你可以试穿
String headerKey = "Content-Disposition";
String headerValue = "attachment; filename=category_list" + ".xlsx";
response.setHeader(headerKey, headerValue);
categoryServiceImpl.exportToExcelFile(response);
添加回答
举报