springboot后端接口直接返回文件数据流
@GetMapping("/aaaaa")
public ResponseEntity<byte[]> getImageAsByteArray(HttpServletResponse response) throws IOException {
ClassPathResource classPathResource = new ClassPathResource("static/aaa.mp3");
InputStream inputStream = classPathResource.getInputStream();
int fileLength = (int) classPathResource.getFile().length();
byte bytes[] = new byte[fileLength];
inputStream.read(bytes);
inputStream.close();
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Disposition", "attachment; filename=\"aaa.mp3\"");
ResponseEntity<byte[]> aaaaa = new ResponseEntity(bytes, headers, HttpStatus.OK);
return aaaaa;
}