当前位置:网站首页>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
边栏推荐
猜你喜欢

Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)

SVG中Path Data数据简化及文件夹所有文件批量导出为图片

SAP PI/PO登录使用及基本功能简介

'NPM' is not an internal or external command, nor is it a runnable program or batch file

Super classic & Programming Guide (red and blue book) - Reading Notes

SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)

SAP ECC连接SAP PI系统配置

SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)

canvas学习第一篇

js之什么是事件?事件三要素以及操作元素
随机推荐
移动布局(flex布局、视口标签)
二叉树的深度
03Scanner类的使用(控制台输入)
SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)
定位、修饰样式
Unable to process jar entry [module info. Class]
NodeJS(四) 字符读取
Scrapy 修改爬虫结束时统计数据中的时间为当前系统时间
解决在docker中部署mysql8, 密码正确但无法登陆MySQL问题
面经的总结
SampleCameraFilter
Unity screen adaptation
设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
异步的学习
Page dynamic display time (upgraded version)
SQL sorts string numbers
js之节点操作,为什么要学习节点操作
移动端布局(3D转换、动画)
取得所有点列表中的最大值GetMaxPoint
Apache Hudi 如何加速传统的批处理模式?