当前位置:网站首页>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
边栏推荐
- Django uses MySQL database to solve error reporting
- SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
- 利用网页表格导出EXCEL表格加线框及表格内部间距的问题
- js之DOM事件
- Processing of common dependency module
- King glory - unity learning journey
- Towords Open World Object Detection
- Install and configure Taobao image NPM (cnpm)
- 基于NLP的软件安全研究(二)
- Common DOS commands
猜你喜欢

将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)

js之排他思想及案例

MySQL8.0 安装/卸载 教程【Window10版】

js之预解析

Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments

Mongodb starts warning information processing

FSM finite state machine

SAP PI/PO功能运行状态监控检查

BTREE, B + tree and hash index

Implementation of MySQL persistence
随机推荐
Use of command line parameter passing library argparse
Nodejs (I) event driven programming
js之DOM学习获取元素
BTREE, B + tree and hash index
TimelineWindow
SVG中Path Data数据简化及文件夹所有文件批量导出为图片
Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight
系统与软件安全研究(二)
Protobuf 使用
Common DOS commands
自己封装unity的Debug函数
canvas学习第一篇
electron-builder打包报错:proxyconnect tcp: dial tcp :0: connectex
Implementation of MySQL persistence
移动端布局(3D转换、动画)
Unity screen adaptation
js中对象的三种创建方式
Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)
学会使用搜索引擎
Ogldev reading notes