Opening a link to download the file

Hey guys.

I have a question which I seem not to be able to find a solution for. I have a table with 2000+ elements which are packages you can download. You can press any of the element and then press a universal download button to download. Well, that is my wish for what it would do.

Essentially the download link is a dynamically created link which i get from a metadatabase. I have everything prepared. I have the button which calls the function void downloadPackage(). This get the information for the link.

My problem is that the link is not a link with a file extension. The link look something like this: https://mylink/package/version. The mylink is a randomstring. This changes every few minute because… reason. So notice how the link doesn’t end with a .zip. This is my problem.

So the only way to download the file for my knowledge, is to open this link manually which will create a new tab to the link, which will then begin downloading the package, which name is also random characters.

My question is: Does there exists some functionality with Vaadin which open this link to download the file without it changing website or open a new tab?

Also to be helpful. I already have the button setup to use

 UI.getCurrent().getPage().open("https://mylink/package/version");

This opens a new tab which download the file and then the user have to manually close the tab. Can this be done without having to open a new tab.

Add an download attribute to the link element. Just the existence of the attribute makes the browser download instead of navigating. You can optionally also set the name that the browser should use as the value of the attribute, e.g. <a href="https://mylink/package/version" download="package-version.zip">Download</a>.

If you have control over the system from where the files are downloaded, then it might also be good to set a Content-Disposition header in the HTTP response.

Check also the brand-new DownloadHandler API: How to download from server to browser in Vaadin