Unable to download files/image for anonymous user - Jmix 2.4.3

Hi,

I have implemented a file download functionality on the click of a button. If I download the file from a normal user who has a proper role assignment then the file gets downloaded properly and can be opened as well. But, when I try to do the same thing from a user with anonymous role then the downloaded file is not getting opened and the file size also differs from the original file.

Please find the below code snippet:

JmixButton button = uiComponents.create(JmixButton.class);
button.setIcon(VaadinIcon.EYE.create());
button.addClickListener(buttonClickEvent -> {
if(path != null)
{
    File file = new File(path);

    FileInputStream inputStream = new FileInputStream(file);

    DownloadDataProvider dataProvider = (() -> inputStream);

    downloader.setShowNewWindow(false);
    downloader.download(dataProvider,file.getName());
}

Getting the below error when opening the file:

Screenshot from 2025-02-18 12-08-39

Analysis done so far:

  1. No relevant logs found like access related issue or anything.
  2. While debugging I observed that, in the JmixFileDownloader class, the code execution stops at the execute() method when anonymous user is downloading and when the normal user downloads, after the execute method the resource.getWriter().accept(stream, VaadinSession.getCurrent()); code gets executed and file gets downloaded. Please find the below code snippet for your refernce.
protected void runCommand(StreamResource resource) {
        contentWriter = (stream) -> {
            try {
                resource.getWriter().accept(stream, VaadinSession.getCurrent());
            } catch (IOException e) {
                throw new RuntimeException("Error copying stream");
            }
        };

        execute();
    }

    protected void execute() {
        getElement().executeJs(CLICK_EXPRESSION);
    }

Thanks in advance. Please let me know if any additional details are required.

Jmix version 2.4.3

Hi!

This is a known issue. Please see the relevant link: Downloader doesn't work in anonymous views · Issue #3285 · jmix-framework/jmix · GitHub
You may find a workaround there.

Best regards,
Dmitriy