小编ek1*_*984的帖子

spring webflux Flux<DataBuffer> 转换为 InputStream

我目前正在研究 Spring WebFlux。我正在尝试使用 Spring WebFlux 上传大文件(70mo)。

我的控制器

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Flux<String> uploadHandler(@RequestBody Flux<Part> fluxParts, @RequestParam(value = "categoryType") String categoryType, @PathVariable(value = "traceabilityReportUuid") String traceabilityUuid) {
    return documentHandler.upload(fluxParts, UUID.fromString(traceabilityUuid), categoryType);
}
Run Code Online (Sandbox Code Playgroud)

我的服务

public Flux<String> upload(Flux<Part> fluxParts, UUID traceabilityUuid, String categoryType) {

    return fluxParts
            .filter(part -> part instanceof FilePart)
            .ofType(FilePart.class)
            .flatMap(p -> this.upload(p, traceabilityUuid, categoryType));


}


private Mono<String> upload(FilePart filePart, UUID traceabilityUuid, String categoryType) {

    return filePart.content().collect(InputStreamCollector::new, (t, dataBuffer) -> t.collectInputStream(dataBuffer.asInputStream()))
            .flatMap(inputStreamCollector -> {
                upload(traceabilityUuid, …
Run Code Online (Sandbox Code Playgroud)

inputstream file flux spring-webflux

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

file ×1

flux ×1

inputstream ×1

spring-webflux ×1