[英]is it possible to open the .pdf file in web browser instead of downloading?
[英]SpringBoot - display PDF-file in browser instead of downloading
我正在尝试使用spring在浏览器中显示pdf。 我的问题是浏览器下载文件而不是显示文件。 这是我的代码:
@RequestMapping(value = "/download" , method=RequestMethod.GET , produces = "application/pdf")
public ResponseEntity<InputStreamResource> downloadPdf() throws IOException {
ClassPathResource pdfFile = new ClassPathResource("TMOBILE.pdf");
return ResponseEntity
.ok()
.contentLength(pdfFile.contentLength())
.contentType(
MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(pdfFile.getInputStream()));
}
我期待着您的答复! 谢谢
将标题更改为此:
Content-Type: application/pdf
Content-Disposition: inline; filename="filename.pdf"
将Content-Type设置为application/octet-stream
将强制其始终下载。
使用Content-Type application/pdf
代替application/octet-stream
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.