美文网首页Spring Boot
Spring WebFlux上传文件

Spring WebFlux上传文件

作者: EasyNetCN | 来源:发表于2023-08-14 17:38 被阅读0次

使用RequestPart接收文件和参数,注意type不能设置为Integer类型

    @PostMapping("/upload")
    public Mono<Result<String>> upload(@RequestPart("file") FilePart file,
            @RequestPart("type") String type) {
    }

转换为byte数组处理

    @PostMapping("/upload")
    public Mono<Result<String>> upload(@RequestPart FilePart file) {
        return DataBufferUtils.join(file.content()).map(dataBuffer -> dataBuffer.asByteBuffer().array()).map(bytes -> {
        });
    }

转换为InputStream处理

    @PostMapping("/upload")
    public Mono<Result<String>> upload( @RequestPart FilePart file) {
        return DataBufferUtils.join(file.content()).map(dataBuffer -> dataBuffer.asInputStream()).map(ins -> {
        });
    }

相关文章

网友评论

    本文标题:Spring WebFlux上传文件

    本文链接:https://www.haomeiwen.com/subject/lujcmdtx.html