Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatic file download support for Hilla endpoints #3131

Open
platosha opened this issue Jan 9, 2025 · 1 comment
Open

Programmatic file download support for Hilla endpoints #3131

platosha opened this issue Jan 9, 2025 · 1 comment
Labels
hilla Issues related to Hilla

Comments

@platosha
Copy link
Contributor

platosha commented Jan 9, 2025

Add support for returning a Spring Resource result from Hilla endpoints. The files should be downloaded using an appropriate HTTP MIME type.

Example endpoint:

@BrowserCallable 
class DownloadEndpoint {
  public Resource loadFile(String fileId) {
    //...
  }
}

TypeScript usage:

const file = await DownloadEndpoint.loadFile("myFile.txt");
const url = URL.createObjectUrl(file);
@platosha platosha added the hilla Issues related to Hilla label Jan 9, 2025
@platosha platosha changed the title File download support for Hilla endpoints Programmatic file download support for Hilla endpoints Jan 9, 2025
@Legioth
Copy link
Member

Legioth commented Jan 9, 2025

Note the point of this API would be to give TypeScript access to the actual bytes of the file. The bytes start being downloaded when the endpoint method is run.

In many cases, you instead want to create a link that the user can click to start a "regular" download. This requires a different mechanism since that link would trigger a GET request which also means that e.g. access control would have to handled without relying on custom request headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hilla Issues related to Hilla
Projects
None yet
Development

No branches or pull requests

2 participants