@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-05-02 21:30:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)