コード
//参数是需要下载的文件路径
@GetMapping("/download")
public ResponseEntity<byte[]> documentList(@RequestParam String documentAccessory) throws IOException {
byte[] data = Files.readAllBytes(Paths.get(documentAccessory));
String fillName = documentAccessory.substring(documentAccessory.lastIndexOf("/") + 1);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentLength(data.length);
headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(fillName, "UTF-8"));
return new ResponseEntity<>(data, headers, HttpStatus.OK);
}
Postmanテスト、
ブラウザテスト、この人生での
永続性または非永続性はひどいものではありません。私は永続性の道を一人で進むことになるのではないかと心配しています。!!