createUploadMiddleware(options?: UploadMiddlewareOptions): MiddlewareFunction
Creates an upload middleware factory.
Checks the declared Content-Length, reads the body once through
ctx.request.bytes() and caps that length against
resolveMaxBodyBytes BEFORE the form is touched, then obtains the
form through the request's formData() accessor — or, when the request
omits that optional member (an out-of-repo IRequest), through the same
shared parseFormBody the accessor itself calls — and enforces
maxSize/allowedMimeTypes/maxFiles on the field's FILE parts before
storing the result under 'storage-plugin:uploads' in ctx.state. Every
refusal short-circuits without calling next. Parsing is the shared one
parse (M94b): a csrfFormMiddleware that already read the same form ahead
of this middleware costs it nothing, because the accessor memoizes. The
policy (every bound and every refusal status) stayed here; only the parse
moved to common.
A part carrying no filename under the field name is a plain form value in
the web standard's terms and is no longer reported as an upload — see the
CHANGELOG migration note.
Refusals are answered 413 when something was too large — the request body
against resolveMaxBodyBytes, or one file against maxSize — and
400 when the request was genuinely malformed or otherwise unacceptable
(too many files, a disallowed MIME type, an unparseable body). Both size
refusals previously answered 400, which told a client it had sent
something malformed when it had only sent something big.
options: UploadMiddlewareOptions
Middleware configuration