A Node.js module for parsing incoming HTML form data.
This is an officially supported fork by fastify organization of the amazing library originally created by Brian White,
aimed at addressing long-standing issues with it.
Benchmark (Mean time for 500 Kb payload, 2000 cycles, 1000 cycle warmup):
file(< string >fieldname, < ReadableStream >stream, < string >filename, < string >transferEncoding, < string >mimeType) - Emitted for each new file form field found. transferEncoding contains the 'Content-Transfer-Encoding' value for the file stream. mimeType contains the 'Content-Type' value for the file stream.
Note: if you listen for this event, you should always handle the stream no matter if you care about the file contents or not (e.g. you can simply just do stream.resume(); if you want to discard the contents), otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about any incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically and safely discarded (these discarded files do still count towards files and parts limits).
If a configured file size limit was reached, stream will both have a boolean property truncated (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.
The property bytesRead informs about the number of bytes that have been read so far.
limit() - Emitted when a file exceeds the configured fileSize limit. You can listen on the file stream to handle it:
limits - object - Various limits on incoming data. Valid properties are:
fieldNameSize - integer - Max field name size (in bytes) (Default: 100 bytes).
fieldSize - integer - Max field value size (in bytes) (Default: 1 MiB, which is 1024 x 1024 bytes).
fields - integer - Max number of non-file fields (Default: Infinity).
fileSize - integer - For multipart forms, the max file size (in bytes) (Default: Infinity).
files - integer - For multipart forms, the max number of file fields (Default: Infinity).
parts - integer - For multipart forms, the max number of parts (fields + files) (Default: Infinity).
headerPairs - integer - For multipart forms, the max number of header key=>value pairs to parse Default: 2000
headerSize - integer - For multipart forms, the max size of a multipart header Default: 81920.
The constructor can throw errors:
Busboy expected an options-Object. - Busboy expected an Object as first parameters.
Busboy expected an options-Object with headers-attribute. - The first parameter is lacking of a headers-attribute.
Limit $limit is not a valid number - Busboy expected the desired limit to be of type number. Busboy throws this Error to prevent a potential security issue by falling silently back to the Busboy-defaults. Potential source for this Error can be the direct use of environment variables without transforming them to the type number.
Unsupported Content-Type. - The Content-Type isn't one Busboy can parse.
Missing Content-Type-header. - The provided headers don't include Content-Type at all.