You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow static filename in DownloadHandler#fromInputStream #22278
Currently the API for downloading an InputStream does not allow setting a static filename. Instead, the filename is part of the DownloadResponse which is returned by the callback. When you download the resource, it makes no difference but if you open the resource in the browser (using inline()), the filename gets lost and the file is typically namend "download".
Describe the solution you'd like
Similar to the additional parameter fileNameOverride in forClassResource an (optional) parameter filename could be provided to forInputStream as well.
Describe alternatives you've considered
My current solution is to create a wrapper for InputStreamDownloadHandler which overrides getUrlPostfix to return the static filename:
public DownloadHandler fromInputStream(InputStreamDownloadCallback callback, String filename) {
return new InputStreamDownloadHandler(callback) {
public String getUrlPostfix() {
return filename;
}
};
}
The disadvantage of this is, that the DownloadResponse could contain a different filename then the one provided in fromInputStream.
There is no additional parameter needed. the problem is inline, which currently does not handle file names - see #21934 (comment) + the following comment by Leif
I thought "inline" cannot be used togerher with a filename and the browser takes it from the URL only. Changing the URL would still not be possible with that but that shouldn't be an issue in most cases.
inline can and should be used together with filename in the Content-Disposition header. Inline is just a hint for a browser that it's preferred to show the content in-browser, instead of starting a download, if possible (browser is able to render that).
If not, though, the browser still needs to know how the downloaded content should be named.
if (!isInline()) {
downloadEvent.setFileName(downloadName);
} else {
downloadEvent.getResponse().setHeader("Content-Disposition", "inline");
}
This causes each inline-tagged download resource (mostly images, I guess) to be downloaded with the name download.[suffix_derived_from_content_type], e.g. download.png when the downloadHandler is created like this:
Activity
knoobie commentedon Sep 16, 2025
There is no additional parameter needed. the problem is inline, which currently does not handle file names - see #21934 (comment) + the following comment by Leif
probert94 commentedon Sep 16, 2025
I thought "inline" cannot be used togerher with a filename and the browser takes it from the URL only. Changing the URL would still not be possible with that but that shouldn't be an issue in most cases.
martintimko-kosik commentedon Jan 29, 2026
inlinecan and should be used together withfilenamein theContent-Dispositionheader. Inline is just a hint for a browser that it's preferred to show the content in-browser, instead of starting a download, if possible (browser is able to render that).If not, though, the browser still needs to know how the downloaded content should be named.
The current implementation in Vaadin goes against it. In InputStreamDownloadHandler.java
here is exclusionary logic:
This causes each inline-tagged download resource (mostly images, I guess) to be downloaded with the name
download.[suffix_derived_from_content_type], e.g.download.pngwhen the downloadHandler is created like this:At least in chromium-based browsers. And it's really weird behaviour, I would say 😬
It should be an easy fix, @mshabarov could you please move the ticket out of Parking lot? 😃
mcollovati commentedon Jan 29, 2026
Contributions are more than welcome 😉
feat: Add overloaded fromInputStream method with fileNameOverride (#2…