denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.06k stars 610 forks source link

Forms page in docs is incorrect about multipart/form-data #2515

Closed jordanbtucker closed 3 weeks ago

jordanbtucker commented 3 weeks ago

There are a few issues with the accuracy of the Forms page, especially regarding multipart/form-data.

Forms can either submit as a GET request with URL search parameter encoding, or as a POST request with multipart/form-data.

This is not true. A form will submit a POST request (when its method attribute is set to post) with an application/x-www-form-urlencoded body by default. To submit a multipart/form-data request, its enctype attribute must be set to multipart/form-data.

The example given in the section POST request with multipart/form-data does not submit a multipart/form-data request. It submits a application/x-www-form-urlencoded request.

I can understand the confusion considering that MDN describes the FormData interface as using "the same format a form would use if the encoding type were set to "multipart/form-data", but that just refers to what happens if you provide a FormData as the body of a request made with fetch. When Deno provides a request to a route handler, its formData() function will resolve to a FormData that is built from the request's body, regardless if it's an application/x-www-form-urlencoded or a multipart/form-data body.

The second example, Handling file uploads, correctly sets the form's enctype to multipart/form-data since that is required for file uploads.