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.
There are a few issues with the accuracy of the Forms page, especially regarding
multipart/form-data
.This is not true. A form will submit a
POST
request (when itsmethod
attribute is set topost
) with anapplication/x-www-form-urlencoded
body by default. To submit amultipart/form-data
request, itsenctype
attribute must be set tomultipart/form-data
.The example given in the section POST request with
multipart/form-data
does not submit amultipart/form-data
request. It submits aapplication/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 aFormData
as the body of a request made withfetch
. When Deno provides a request to a route handler, itsformData()
function will resolve to aFormData
that is built from the request's body, regardless if it's anapplication/x-www-form-urlencoded
or amultipart/form-data
body.The second example, Handling file uploads, correctly sets the form's
enctype
tomultipart/form-data
since that is required for file uploads.