alexanoid
alexanoid

Reputation: 25852

Vaadin 24 file-download-wrapper component

I need to download a file by Button click in Vaadin Flow 24 application. For this purpose, I installed https://vaadin.com/directory/component/file-download-wrapper helper add-on.

Everything works fine on desktop browser but when I use my iPhone, I click the download button on the View, let's say on the following page:

https://example.com/products/02c898e8-4239-4153-9bf5-30faa0bb2a25

in order to download a PDF file. After that, I successfully see the PDF file on the screen. But the issue is that the URL of the page is changed now to:

https://example.com/VAADIN/dynamic/resource/3/55c74517-4ac0-42ca-81fe-0a3e62ff3bca/product.pdf

which is something that I don't expect. I noticed this when I tried to share the download file to another user. Instead of the file, I sent to this user the URL https://example.com/VAADIN/dynamic/resource/3/55c74517-4ac0-42ca-81fe-0a3e62ff3bca/product.pdf

The biggest issue here is that the page https://example.com/VAADIN/dynamic/resource/3/55c74517-4ac0-42ca-81fe-0a3e62ff3bca/product.pdf doesn't exists and this will confuse the user. They will share the "dead" urls.

Is this a correct behavior on iPhone and if no, what am I doing wrong? Is it possible to somehow improve the user experience in this case and not show them such a URL https://example.com/VAADIN/dynamic/resource/3/55c74517-4ac0-42ca-81fe-0a3e62ff3bca/product.pdf ?

This is the code:

Button button= new Button("Download file");
FileDownloadWrapper wrapper= new FileDownloadWrapper(
    new StreamResource("product.pdf", () -> {
         try {
               return productService.generateFileInputStream();
         } catch (IOException e) {
              throw new RuntimeException(e);
         }
    }));
wrapper.wrapComponent(button);
layout.add(wrapper);

Upvotes: 0

Views: 2286

Answers (1)

Knoobie
Knoobie

Reputation: 2064

Stream resources / dynamic URLs are UI based and can't be shared. When a legitimate use case of your users is to share dynamically created files, you have to use e.g. a spring controller or servlet to serve them and just use an Anchor on Vaadin that links to that particular resource. Make sure to apply proper security to that endpoint / or not if it's allowed to be accessed by anyone.

Upvotes: 4

Related Questions