A Promise based version of busboy
Parter uses busboy under the hood. In fact, parter is written to make busboy promise based. To install parter, run
yarn add parteror,
npm install parterNow, you can import it and instantiate it,
import parter from 'parter';
async function requestHandler(req, res){
// other things
const body = await parter(req);
// other things
}When we try to log body, we will get an object similar to this
{
fields:{
name: <String>,
value: <String>,
info: <Object>
},
files:{
name: <String>,
content: <Buffer>,
info: <Object>
}
}Notice, we pass in req as the first argument. The req we pass in must be an instance of
IncomingMessage from node http module or it can be an instance of Request constructor.
You can also pass in an abject as a second parameter. This object is to configure parter.
As, parter uses busboy, this is the same configuration object you would pass
in busboy. But, you can, of course pass additional properties.
options.errorOnMoreFields = <Boolean>
options.errorOnMoreFiles = <Boolean>
options.errorOnMoreParts = <Boolean>
options.errorOnLargerFileSize = <Boolean>-
errorOnMoreFieldsWhether to reject if `fieldsLimit` is emitted from busboy -
errorOnMoreFilesWhether to reject if `filesLimit` is emitted from busboy -
errorOnMorePartsWhether to reject if `partsLimit` is emitted from busboy -
errorOnLargerFileSizeWhether to reject if `limit` is emitted from busboy.