我目前正在研究 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)