FormData API. Let’s start with a HTTP server that serves a simple HTML web form.
We can define our HTML form in another file,
index.html.
index.html
At this point, we can run the server and visit
localhost:4000 to see our form.
Our form will send a
POST request to the /action endpoint with the form data. Let’s handle that request in our server.
First we use the .formData() method on the incoming Request to asynchronously parse its contents to a FormData instance. Then we can use the .get() method to extract the value of the name and profilePicture fields. Here name corresponds to a string and profilePicture is a Blob.
Finally, we write the Blob to disk using Bun.write().