上传文件而不将其下载到手机上

时间:2018-07-11 08:15:30

标签: java spring spring-boot file-upload

我在春季有休息服务,可以上传PDF文件。在浏览器上,它工作正常(仅应显示pdf)。但是,当我在手机上输入URL时,它想先下载文件。只能在移动设备上查看PDF吗?

这是我的控制器:

@ResponseBody
@GetMapping(value = "/term", produces = MediaType.APPLICATION_PDF_VALUE)
public ResponseEntity<byte[]> getTermAndConditions() {
    String uploadsFolder = "content";
    String fileName = "TermsAndCond.pdf";
    byte[] bytes = fileService.getBytes(fileName, uploadsFolder);
    if (bytes != null) {
        return new ResponseEntity<>(bytes, HttpStatus.OK);
    }
    return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

我尝试添加标题:

response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline; filename=\"TermsAndCond.pdf\"");

response.setHeader("Content-Disposition", "inline");

但这没有帮助。

0 个答案:

没有答案