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

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

canvas学习第一篇

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

向量到一个平面的投影向量

Configure NPM

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

SAP Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。

企业微信免登录跳转自建应用

ABAP 7.4 SQL Window Expression

C# 多个矩形围成的多边形标注位置的问题
随机推荐
SQL sorts string numbers
大学学习路线规划建议贴
反转链表练习
向量到一个平面的投影向量
Thorough inquiry -- understanding and analysis of cocos2d source code
颜色转换公式大全及转换表格(31种)
'NPM' is not an internal or external command, nor is it a runnable program or batch file
Page dynamic display time (upgraded version)
Date object (JS built-in object)
One of event management
ABAP 从CDS VIEW 发布OData Service示例
js之函数的两种声明方式
面经的总结
js之排他思想及案例
SAP CR传输请求顺序、依赖检查
Use of typescript dictionary
Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)
BTREE, B + tree and hash index
踩坑日记:Unable to process Jar entry [module-info.class]
使用flask时代码无报错自动结束,无法保持连接,访问不了url。