当前位置:网站首页>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
边栏推荐
- ABAP 从CDS VIEW 发布OData Service示例
- MySQL isolation level
- 命令行参数传递库argparse的使用
- Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
- 踩坑日记:Unable to process Jar entry [module-info.class]
- 'NPM' is not an internal or external command, nor is it a runnable program or batch file
- Simple random roll call lottery (written under JS)
- 取得所有点列表中的最大值GetMaxPoint
- 颜色转换公式大全及转换表格(31种)
- 斐波拉去动态规划
猜你喜欢
对复杂字典Dictionary&lt;T1,T2&gt;排序问题
Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments
canvas学习第一篇
Super classic & Programming Guide (red and blue book) - Reading Notes
SAP PI/PO登录使用及基本功能简介
H5 local storage data sessionstorage, localstorage
Window10版MySQL设置远程访问权限后不起效果
MySQL index
Mongodb starts warning information processing
js之排他思想及案例
随机推荐
State synchronization and frame synchronization
Nodejs (I) event driven programming
C# SmoothProgressBar自定义进度条控件
使用flask时代码无报错自动结束,无法保持连接,访问不了url。
js案例之求最大值,反转数组,冒泡排序
将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)
SVG中Path Data数据简化及文件夹所有文件批量导出为图片
Window10版MySQL设置远程访问权限后不起效果
Mongodb starts warning information processing
.NET 5 的新功能 What‘s new in .NET 5
系统与软件安全研究(三)
系统与软件安全研究(四)
Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments
H5 local storage data sessionstorage, localstorage
根据某一指定的表名、列名及列值来向前或向后N条查相关列值的SQL自定义标量值函数
new的实现
防抖和节流
Rethink | open the girl heart mode of station B and explore the design and implementation of APP skin changing mechanism
系统与软件安全研究(五)
取得所有点列表中的最大值GetMaxPoint