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