@RequestMapping("/{filename}")
public ResponseEntity<byte[]> download(@PathVariable String filename) throws IOException {
ResponseEntity<byte[]> entity = null;
try {
HttpHeaders headers = new HttpHeaders();
String pathname = getFilepath(filename);
File file = new File(pathname);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
entity = new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
return entity;
} catch (IOException e) {
logger.error(e.getMessage());
throw e;
}
}
原文地址:https://blog.51cto.com/14220961/2365598
时间: 2024-10-04 21:10:53