0
@GetMapping(值= “/图片”,产生= “应用程序/ PDF格式”) @ResponseBody 公共字符串downloadFile(@PathVariable( “路径”)字符串路径)抛出IOException异常{ClassPathResource downloadLink = new ClassPathResource(“/ assets /”+ path);如何从Web服务下载图像/ PDF文件中的Spring应用程序
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/pdf"));
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Methods", "GET, POST, PUT");
headers.add("Access-Control-Allow-Headers", "Content-Type");
headers.add("Content-Disposition", "filename=" + path);
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
headers.setContentLength(downloadLink.contentLength());
Base64.getDecoder().decode(path);
return "/admin/image";
}
时,出现了base64字符串,我需要将其转换为文件并在html页面上呈现。我无法看到代码 –
中的转换,您可以在解码后发送数据:'ResponseEntity response = new ResponseEntity (new String(Base64.getDecoder()。decode(pdfFile.getInputStream()。toString())),headers, HttpStatus.OK); ' –
Sharma