Skip to content

Commit 0608da9

Browse files
geoandFroMage
andcommitted
Add example of sending back a file with RestResponse
Relates to: #50317 Co-authored-by: Stéphane Épardaud <[email protected]>
1 parent 12c1df0 commit 0608da9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/src/main/asciidoc/rest.adoc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,34 @@ public class Endpoint {
778778
NOTE: You can also use the Jakarta REST type link:{jaxrsapi}/jakarta/ws/rs/core/Response.html[`Response`] but it is
779779
not strongly typed to your entity.
780780

781+
==== Responding with files
782+
783+
When a file needs to be returned, the following code ensures that Quarkus properly streams the file contents to the client.
784+
785+
[source,java]
786+
----
787+
package org.acme.rest;
788+
789+
import jakarta.ws.rs.GET;
790+
import jakarta.ws.rs.Path;
791+
import org.jboss.resteasy.reactive.RestResponse;
792+
import org.jboss.resteasy.reactive.RestResponse.ResponseBuilder;
793+
794+
@Path("")
795+
public class Endpoint {
796+
797+
@Path("file")
798+
@GET
799+
public RestResponse<java.nio.file.Path> largePathRestResponse() throws IOException {
800+
java.nio.file.Path path = ...
801+
802+
return RestResponse.ResponseBuilder.ok(path)
803+
.header(HttpHeaders.CONTENT_DISPOSITION, "some-file-name")
804+
.build();
805+
}
806+
}
807+
----
808+
781809
==== Using annotations
782810

783811
Alternatively, if you only need to set the status code and / or HTTP headers with static values, you can use `@org.jboss.resteasy.reactive.ResponseStatus` and /or `ResponseHeader` respectively.

0 commit comments

Comments
 (0)