想在浏览器里直接GET目标URL,然后就把PDF在浏览器里预览出来(不用前端插件的前提下),就像这样:
后端代码:
@RequestMapping(value = "/showPDF", method = RequestMethod.GET)
public ResponseEntity pdfDownload(
HttpServletRequest httpServletRequest
) throws IOException
{
String path = XXX省略。。。
File file = new File(path);
HttpHeaders httpHeaders = new HttpHeaders();
String fileName = file.getName();
httpHeaders.setContentDispositionFormData("attachment", java.net.URLEncoder.encode(fileName,"UTF-8"));
httpHeaders.setContentType(MediaType.parseMediaType("application/pdf"));
return new ResponseEntity(FileUtils.readFileToByteArray(file),
httpHeaders,
HttpStatus.CREATED);
}
然后想在前端直接GET这个URL地址:
http://localhost:8080/FileUpDown/showPDF
但是却成了下载文件而不是预览