parseFormData
Summary
Parses a Request body into a FormData
object. This is useful when accessing the data contained in a HTTP multipart/form-data request
generated by a HTML <form> element.
This is a drop-in replacement for the built-in request.formData() API
with the main difference being the ability to customize the handling of file uploads. Instead of
keeping all files in memory, the uploadHandler receives each file as soon as its headers
arrive and can stream it to disk or a cloud storage service.
Parts are read in order, so the parser waits for the uploadHandler, and for any read of the
upload it started, to finish before moving on. Contents the handler doesn't read are discarded.
If the handler returns the upload itself, it is read into memory and stored as a File.
Accepts multipart/* and application/x-www-form-urlencoded media types.
Unsupported media types throw FormDataParseError before the body is read.
Signature
function parseFormData(request: Request, uploadHandler: FileUploadHandler): Promise<FormData>
function parseFormData(
request: Request,
options: ParseFormDataOptions,
uploadHandler: FileUploadHandler,
): Promise<FormData>
Parameters
request
The Request object to parse
options
Options for the parser
uploadHandler
A function that handles file uploads. It receives a FileUpload and may return any value that is valid in a FormData object