@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用二进制的方式返回文件流
最新推荐文章于 2025-02-23 19:23:55 发布