当前位置:网站首页>webflux文件上传下载
webflux文件上传下载
2022-04-23 06:28:00 【夜夜夜空】
文件上传:
@PostMapping(value = "/upload")
public Mono<String> requestBodyFlux(@RequestPart("filePart") FilePart filePart) throws IOException {
System.out.println(filePart.filename());
Path tempFile = Files.createTempFile("tmp", filePart.filename());
//NOTE 方法一
AsynchronousFileChannel channel =
AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE);
DataBufferUtils.write(filePart.content(), channel, 0)
.subscribe();
//NOTE 方法二
// filePart.transferTo(tempFile.toFile());
System.out.println(tempFile.toString());
return Mono.just(filePart.filename());
}
文件下载:
@GetMapping("/download")
public Mono<Void> downloadByWriteWith(ServerHttpResponse response) throws IOException {
ZeroCopyHttpOutputMessage zeroCopyResponse = (ZeroCopyHttpOutputMessage) response;
response.getHeaders().set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=cert.crt");
response.getHeaders().setContentType(MediaType.APPLICATION_OCTET_STREAM);
Resource resource = new ClassPathResource("cert.crt");
File file = resource.getFile();
return zeroCopyResponse.writeWith(file, 0, file.length());
}
版权声明
本文为[夜夜夜空]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zixuanyankai/article/details/120343450
边栏推荐
猜你喜欢

Authorization+Token+JWT

ABAP 7.4 SQL Window Expression

中间人环境mitmproxy搭建

基于NLP的软件安全研究(一)

SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)

SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)

Implementation of MySQL persistence

防抖和节流

命令行参数传递库argparse的使用

Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight
随机推荐
Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments
Implementation of MySQL persistence
移动布局(flex布局、视口标签)
SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)
FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
将单行文字自动适应到目标矩形框内
ES6使用递归实现深拷贝
js之DOM学习三种创建元素的方式
Common DOS commands
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
Scrapy modifies the time in the statistics at the end of the crawler as the current system time
C# 多个矩形围成的多边形标注位置的问题
Preliminary configuration of OpenGL super Dictionary (freeglut, glew, gltools, GLUT)
js之排他思想及案例
new的实现
Online Safe Trajectory Generation For Quadrotors Using Fast Marching Method and Bernstein Basis Poly
Unable to process jar entry [module info. Class]
快排的练习
MySQL8.0 安装/卸载 教程【Window10版】
向量到一个平面的投影向量