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

File upload support for Hilla endpoint controller #3130

Open
platosha opened this issue Jan 9, 2025 · 0 comments
Open

File upload support for Hilla endpoint controller #3130

platosha opened this issue Jan 9, 2025 · 0 comments
Labels
hilla Issues related to Hilla

Comments

@platosha
Copy link
Contributor

platosha commented Jan 9, 2025

Add runtime support for parameters of type MultipartFile in Hilla endpoint controller.

The files should be uploaded using HTTP multipart/form-data encoding. Note that the encoding changes from the regular application/json when requests contain file parameters.

Users can add additional parameters and return any Hilla supported result type in the same endpoint.

At the same time, let us add integration tests.

Example endpoint:

@BrowserCallable
class AppEndpoint {
  public void saveFile(MultipartFile file) {
  }

  public String saveFileAsUrl(MultipartFile file) {
    file.transferTo(...);
    return "https://...";
  }

  public void saveUserWithAvatar(UserData user, MultipartFile avatar) {
  }

  public void saveAvatarWithThumbnail(MultipartFile avatar, MultipartFile thumbnail) {
  }

  public ValueSignal<FileProcessingProgress> saveAndConvertHugeFile(MultipartFile hugeFile) {
  }
}

TypeScript usage:

export default function UploadForm({}) {
  const [uploadState, setUploadState] = useState("");

  const uploadFile = useCallback(async (event: SubmitEvent) => {
    event.preventDefault();
    const file = new FormData(event.target).get("file");
    await AppEndpoint.saveFile(file);
    setUploadState("ok!");
  });

  return <form onSubmit={uploadFile}>
    <input type="file" name="file" />
    <button type="submit">Upload</button>
    <output>{uploadState}</output>
  </form>;
}
@platosha platosha added the hilla Issues related to Hilla label Jan 9, 2025
@platosha platosha changed the title File upload for Hilla endpoints File upload support for Hilla endpoints Jan 9, 2025
@platosha platosha changed the title File upload support for Hilla endpoints File upload support for Hilla endpoint controller Jan 9, 2025
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

1 participant