-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebFlux multipart streaming not work #26567
Comments
The streaming mode of the In order to make it work, I had to change the @Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
DefaultPartHttpMessageReader partReader = new DefaultPartHttpMessageReader();
partReader.setStreaming(true);
configurer.customCodecs()
.register(partReader);
} I had to change the controller to @RestController
@RequestMapping("api/v1/files")
public class FilesController {
@PostMapping
public Flux<String> upload(@RequestBody Flux<Part> parts) {
return parts.flatMap(part -> {
if (part instanceof FilePart) {
FilePart filePart = (FilePart) part;
String filename = filePart.filename();
return createTempFile("test", filename)
.flatMap(filePart::transferTo)
.then(Mono.just(filename));
} else {
return part.content().map(DataBufferUtils::release)
.then(Mono.empty());
}
});
}
private static Mono<Path> createTempFile(String prefix, String suffix) {
return Mono.fromCallable(() -> Files.createTempFile(prefix, suffix))
.subscribeOn(Schedulers.boundedElastic());
}
} There are a couple of things to note here:
We are considering ways to improve this rough experience in an upcoming version, allowing for code similar to your initial version, but the "read-once" attribute of streaming mode makes things quite complex. |
I just tested this and a temporary folder is still being create :( |
@poutsma, hello! You could enable streaming like this: @Configuration
public class StreamingCodecConfig implements WebFluxConfigurer {
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer config) {
config.defaultCodecs().multipartReader(new MultipartHttpMessageReader(defaultPartHttpMessageReader()));
}
public DefaultPartHttpMessageReader defaultPartHttpMessageReader() {
DefaultPartHttpMessageReader defaultPartHttpMessageReader = new DefaultPartHttpMessageReader();
defaultPartHttpMessageReader.setStreaming(true);
return defaultPartHttpMessageReader;
}
} But according to #27743 - request will hang forever (at least for me and @jomach). |
I want to upload files without saving to disk or memory.
Controller:
Config:
Request:
Full example:
streaming-multipart.zip
The text was updated successfully, but these errors were encountered: