当前位置:网站首页>Weblux file upload and download
Weblux file upload and download
2022-04-23 07:49:00 【Night sky】
Upload files :
@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 Method 1
AsynchronousFileChannel channel =
AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE);
DataBufferUtils.write(filePart.content(), channel, 0)
.subscribe();
//NOTE Method 2
// filePart.transferTo(tempFile.toFile());
System.out.println(tempFile.toString());
return Mono.just(filePart.filename());
}
File download :
@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());
}
版权声明
本文为[Night sky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230627211336.html
边栏推荐
猜你喜欢
MySQL in window10 version does not work after setting remote access permission
【NLP笔记】CRF原理初探
基于NLP的软件安全研究(二)
平面定义-平面方程
Install and configure Taobao image NPM (cnpm)
ABAP 7.4 SQL Window Expression
将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)
命令行参数传递库argparse的使用
设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
Mongodb starts warning information processing
随机推荐
学会使用搜索引擎
Thorough inquiry -- understanding and analysis of cocos2d source code
js之什么是事件?事件三要素以及操作元素
ES6 uses recursion to implement deep copy
简单理解==和equals,String为什么可以不用new
命令行参数传递库argparse的使用
UnityShader基础
MySQL8.0 安装/卸载 教程【Window10版】
SAP PI/PO功能运行状态监控检查
ABAP 7.4 SQL Window Expression
Common DOS commands
C# 多个矩形围成的多边形标注位置的问题
Xamarin版的C# SVG路径解析器
Samplecamerafilter
canvas学习第一篇
4. Multi table query
js之函数的两种声明方式
大学学习路线规划建议贴
移动端布局(3D转换、动画)
Mobile game performance optimization