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

SAP ECC连接SAP PI系统配置

Redis connection error err auth < password > called without any password configured for the default user

King glory - unity learning journey

Ogldev reading notes

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

基于NLP的软件安全研究(二)

int a = 1存放在哪

Scrapy modifies the time in the statistics at the end of the crawler as the current system time

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

Django uses MySQL database to solve error reporting
随机推荐
RGB颜色转HEX进制与单位换算
electron-builder打包报错:proxyconnect tcp: dial tcp :0: connectex
Unable to process jar entry [module info. Class]
Double sided shader
SAP Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。
url转成对象
SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)
Dropping Pixels for Adversarial Robustness
系统与软件安全研究(五)
C# 读取注册表
SAP PI/PO功能运行状态监控检查
Simple random roll call lottery (written under JS)
根据某一指定的表名、列名及列值来向前或向后N条查相关列值的SQL自定义标量值函数
Xamarin版的C# SVG路径解析器
Towords Open World Object Detection
js之排他思想及案例
SQL针对字符串型数字进行排序
基于NLP的软件安全研究(一)
Nodejs (I) event driven programming
12. Constraints