Skip to content
Advertisement

Convert Flux into Flux

I am working on spring webflux file upload. From the controller I want to upload the file on amazon S3 bucket. So in the controller I received following object

org.springframework.http.codec.multipart.FilePart

And from the FilePart.content() I can get

reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>

My question is how can I convert this Flux<DataBuffer> into Flux<ByteBuffer>. I mean into the following object

Flux<java.nio.ByteBuffer>

Advertisement

Answer

You can simply use the org.springframework.core.io.buffer.DataBuffer#asByteBuffer():

Flux<java.nio.ByteBuffer> buffers = filePart.content()
    .map(DataBuffer::asByteBuffer);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement