Spring Boot

Spring WebFlux上传文件

2023-08-14  本文已影响0人  EasyNetCN

使用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 -> {
        });
    }
上一篇 下一篇

猜你喜欢

热点阅读