FileDownloadWrapper.setFilename does not change StreamResource filename, always downloads with the name from StreamResource constructor.
Is this bug or feature (and I’m missing something?)
Vaadin 14.0.15
FDW 3.0.1
FileDownloadWrapper.setFilename does not change StreamResource filename, always downloads with the name from StreamResource constructor.
Is this bug or feature (and I’m missing something?)
Vaadin 14.0.15
FDW 3.0.1
Do you have a small example to reproduce this? It sounds like a bug.
Button button = ComponentHelper.getPrimaryButton("XLS Report", false);
StreamResource streamResource = new StreamResource("Report.xlsx", () -> {
...
});
FileDownloadWrapper buttonWrapper = new FileDownloadWrapper(streamResource);
buttonWrapper.wrapComponent(button);
buttonWrapper.setFileName("test.xlsx");
After clicking on XLS Report, Report.xlsx is downloaded. Looks like because of StreamResourceRegistry
Vaadin 14.0.15;
FileDownloadWrapper 3.0.1
Ah, yes, you’re right. If you’re creating a StreamResource
, it includes its own file name and that’s not changeable later. You need to provide a new StreamResource if you want to change the name. Might be that FileDownloadWrapper should throw an IllegalStateException in this scenario.
So what is the correct solution for downloadable file with dynamic filename?
Create a new StreamResource
with the new name and use fileDownloadWrapper.setResource(streamResourceWithNewName);