Skip to content

Allow static filename in DownloadHandler#fromInputStream #22278

Description

@probert94

Describe your motivation

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.

Activity

  1. knoobie commented on Sep 16, 2025

    @knoobie
    Contributor

    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

  2. probert94 commented on Sep 16, 2025

    @probert94
    Author

    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.

  3. moved this from 🪵Product backlog to 🅿️Parking lot in Vaadin Flow | Hilla | Kits ongoing workon Dec 18, 2025
  4. martintimko-kosik commented on Jan 29, 2026

    @martintimko-kosik

    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.

    The current implementation in Vaadin goes against it. In InputStreamDownloadHandler.java
    here is exclusionary logic:

    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:

    DownloadHandler.fromInputStream {
        DownloadResponse(data.inputStream(), "test.png", "image/png", data.size.toLong())
    }
    

    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? 😃

  5. mcollovati commented on Jan 29, 2026

    @mcollovati
    Collaborator

    Contributions are more than welcome 😉

  6. added a commit that references this issue on Apr 1, 2026
    cb0bf0f
  7. moved this from Maybe to Done / Pending Release in Vaadin Flow enhancements backlogon Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions