AnchorLink e download file

I’ve created a dialog with an anchor link that allows me to download a file. Now the anchor link not only downloads the file for me but also opens it in a new tab. Is it possible to download it without opening it?

Does your anchor have the download attribute set?

Yes.Anchor link = new Anchor(streamResource, String.format(“%s (%d KB)”, downloadFilename, (int) downloadFilename.length() / 1024));
// link.getElement().setAttribute(“download”, true);

Some Browser ignore download if they know what they wanna do with the file - for example PDFs are often directly shown to the user. Only workaround is to trick the Browser that it’s not a PDF, like using another mime type

It’s commented out here

The comment was copied by mistake, it was not commented