0
@GetMapping(値= "/ image"、生成= "application/pdf") @ResponseBody public String downloadFile(@PathVariable( "path")Stringパス)がIOExceptionをスローする{ ClassPathResource downloadLink =新しいClassPathResource( "/ assets /" +パス);春のアプリケーションで画像/ PDFファイルをWebサービスからダウンロードする方法
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";
}
Amはなってこのコードを参照することができます私はファイルに変換してHTMLページでレンダリングする必要があるbase64文字列です。私はコードでの変換を見ることができません –
あなたはデコード後にデータを送信することができます: 'ResponseEntity response = new ResponseEntity (new String(Base64.getDecoder()。decode(pdfFile.getInputStream()。toString())) HttpStatus.OK); ' –
Sharma