@GetMapping("/Download/wpqr/{type}/{fileName}")
public ResponseEntity<Resource> wpqrDownloadFile(@PathVariable("type") String type, @PathVariable("fileName") String fileName) throws DataException, IOException {
String filePath = getFilePath(type.toLowerCase());
Path path = Paths.get(filePath, fileName);
Resource resource = new InputStreamResource(Files.newInputStream(path));
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")
.body(resource);
}
SringBoot用二进制的方式返回文件流
最新推荐文章于 2024-07-04 14:43:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)