Skip to content
Advertisement

How to serve files/PDF files the reactive way in spring

I have the following endpoint code to serve PDF files.

JavaScript

How can I convert above into a reactive type Flux/Mono and DataBuffer.

I have check DataBufferUtils but It doesn’t seem to offer what I needed. I didn’t find any example either.

Advertisement

Answer

The easiest way to achieve that would be with a Resource.

JavaScript

Note that DataBufferUtils has some useful methods there that convert an InputStream to a Flux<DataBuffer>, like DataBufferUtils#read(). But dealing with a Resource is still superior.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement