想在浏览器里直接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
但是却成了下载文件而不是预览了。。。
这是chrome的输出:
**Response Headers**
*view source
Content-Disposition:form-data; name="attachment"; filename="1472111731322JavaScript%E6%9D%83%E5%A8%81%E6%8C%87%E5%8D%97.pdf"
Content-Length:21962427
Content-Type:application/octet-stream;charset=UTF-8
Date:Thu, 25 Aug 2016 08:32:56 GMT
Server:Apache-Coyote/1.1*
Conrent-Type明显不对,请问该如何解决?