@PostMapping("/")
@ResponseBody
ResponseEntity<StreamingResponseBody> post(@RequestPart final MultipartFile file)
throws Exception {
if (file.isEmpty()) {
throw new ValidationException("file was empty");
}
final HttpHeaders headers = new HttpHeaders();
headers.setContentDispositionFormData("filename", "sample.txt");
final StreamingResponseBody body = out -> out.write(file.getBytes());
return ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.valueOf("application/force-download"))
.body(body);
}
DemoApplication.java 文件源码
java
阅读 42
收藏 0
点赞 0
评论 0
项目:spring-boot-sandbox
作者:
评论列表
文章目录