restify-multipart-body-parser

Configurable multipart body parser middleware for restify

Usage no npm install needed!

<script type="module">
  import restifyMultipartBodyParser from 'https://cdn.skypack.dev/restify-multipart-body-parser';
</script>

README

restify-multipart-body-parser

Configurable multipart body parser (based on busboy) middleware for restify.

Configuration

{
  auto: { // Automatic parsing
    fields: true
  },
  multipart: true, // Multipart content parsing
  urlencoded: true, // Urlencoded content parsing
  encoding: 'utf8', // Default encoding

  // Parser limits (busboy)
  limits: {
    fieldNameSize: 100, // Max field name size (Default: 100 bytes).
    fieldSize: 1024 * 1024, // Max field value size (Default: 1MB)
    fields: undefined, // Max number of non-file fields (Default: Infinity).
    fileSize: undefined, // For multipart forms, the max file size (Default: Infinity).
    files: undefined, // For multipart forms, the max number of file fields (Default: Infinity).
    parts: undefined, // For multipart forms, the max number of parts (fields + files) (Default: Infinity).
    headerPairs: 100 // For multipart forms, the max number of header key=>value pairs to parse Default: 2000 (same as node's http).
  }
}

Usage

server.put('/multipart', function (req, res, next) {
  req.on('fields', function onFields (fields) {
    // Or req.params
  });

  req.on('file', function onFile (field, file, filename, encoding, mimetype) {
    // Directly proxied from busboy
  });

  req.on('finish', function onFinish () {
    // Finished
  })
});

TODO

  • Switch from busboy to custom parser (to lightly abstracted dicer based parser?)
  • Automatic files parsing and saving to the local filesystem