spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Improve documentaton on controller return values for file downloads

Open verils opened this issue 2 months ago • 4 comments

I've updated the documentation to indicate that a ResponseEntity<Resource> can be returned from a WebFlux controller.

On a separate note, since file uploads and downloads are common requirements in the Spring framework, I believe it would be beneficial to create a dedicated page to guide developers through the process. I'd be happy to create one. What are your thoughts?

verils avatar Nov 05 '25 11:11 verils

On a separate note, since file uploads and downloads are common requirements in the Spring framework, I believe it would be beneficial to create a dedicated page to guide developers through the process.

We have Multipart Content for WebFlux and similar for WebMvc that cover uploads. Renaming that to Multipart Uploads, and creating another on Multipart Downloads would be fine.

rstoyanchev avatar Nov 18 '25 10:11 rstoyanchev

Initially, the issue I encountered was that I didn't know how to handle content downloads in WebFlux, as there was no clear explanation in the documentation. I did some search online and finally found out that returning ResponseEntity<Flux<DataBuffer>> is the best option for me. Therefore, my main goal is to clarify it, the DataBuffer section is very close to the truth but isn't explicit enough.

As @rstoyanchev pointed out, the Return Values section is the best place to address this, I'm gonna add a Flux<DataBuffer> line to that table.

I also used Resource for a while but encountered a side effect: the ResourceHttpMessageWriter (in WebFlux) and the ResourceHttpMessageConverter (in WebMvc) automatically override the response's Content-Type with media type from the Resource. This can break an application/octet-stream download, and this behavior should also be documented.

verils avatar Nov 18 '25 15:11 verils

@verils, I don't think we should avoid documenting returning Resource as a way to handle downloads just because of an issue you ran into. The issue should be considered to decide whether it is intentional, a limitation, something that needs fixing, and so on.

I will say briefly that if the returned ResponseEntity has the content-type set then I would expect it to get used. However, I would also want to know why the content type of the resource isn't the right one to begin with. This is best discussed in a separate issue.

rstoyanchev avatar Nov 18 '25 17:11 rstoyanchev

@rstoyanchev Yes, I agree that.

So I'll just deal with the return type list first.

verils avatar Nov 19 '25 02:11 verils