DemoApplication.java 文件源码

java
阅读 42 收藏 0 点赞 0 评论 0

项目:spring-boot-sandbox 作者:
@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);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号