-
Notifications
You must be signed in to change notification settings - Fork 175
Download handler #21166
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
Labels
Comments
caalador
added a commit
that referenced
this issue
Apr 11, 2025
Add DownloadHandler interface and factory methods. Closes #21166
caalador
added a commit
that referenced
this issue
Apr 11, 2025
Add DownloadHandler interface and factory methods. Closes #21166
caalador
added a commit
that referenced
this issue
Apr 11, 2025
Add DownloadHandler interface and factory methods. Closes #21166
caalador
added a commit
that referenced
this issue
Apr 14, 2025
Add DownloadHandler interface and factory methods. Closes #21166
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe your motivation
Using an
OutputStream
in API for downloads is preferable as this is more intuitive when your server-side code wants to downstream data to client, better aligned with the Servlet API.Describe the solution you'd like
StreamResource
is deprecated and a newDownloadHandler
concept is introduced as a replacement:This is a layer on top of the generic element-scoped request handler with helpers to give easy access to file reference, class-path resource, servlet context resource or arbitrary input stream.
The optional URL postfix allows appending an application-controlled string, e.g. the logical name of the target file, to the end of the otherwise random-looking download URL. If defined, requests that would otherwise be routable are still rejected if the postfix is missing or invalid.
Just like with
StreamResource
, the framework should do the regular security checks before invoking the handler. The session is not locked while the handler is run. The handler may lock the session if necessary but it's not recommended to hold the lock while writing data to the response.All the magic is in the event object. It gives direct access to the underlying request, response and session as well as various helpers specifically for handling downloads.
DownloadHandler
can be used with various component, e.g.Anchor
,Image
and others:In addition to the callback method, the
DownloadHandler
interface also defines factory methods for creating a download handler instance for various common use cases.The
DownloadResponse
return type allows providing anInputStream
to read from or aConsumer<OutputStream>
to acquire a stream to write to.The text was updated successfully, but these errors were encountered: