/**
* 下载文件
*
* @param filepath
* @throws WiiException
*/
@ApiOperation("下载文件")
@GetMapping(path = "/doc_download")
public ResponseEntity<FileSystemResource> downloadFile(@RequestParam("filepath") @ApiParam(name="文件路径",value = "传入json") String filepath) {
String decodeFile = URLDecoder.decode(filepath);
return export(new File(decodeFile));
}
public ResponseEntity<FileSystemResource> export(File file) {
if (file == null) {
return null;
}
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", "attachment; filename=" + file.getName());
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
headers.add("Last-Modified", new Date().toString());
headers.add("ETag", String.valueOf(System.currentTimeMillis()));
return ResponseEntity
.ok()
.headers(headers)
.contentLength(file.length())
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new FileSystemResource(file));
}
springboot文件下载
最新推荐文章于 2024-07-16 12:38:00 发布