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

Client support for file upload with Hilla endpoints #3132

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

Client support for file upload with Hilla endpoints #3132

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

Extracted from #3130

When given at least one parameter of type File, the endpoint client should use multipart/form-data request type and include all parameters with their name, including all files.

Unit-testing is enough for the client part.

Example 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
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