busboy-promise

Promisified multipart collection using Busboy

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
busboy-promise
210.0.38 years ago8 years agoMinified + gzip package size for busboy-promise in KB

Readme

busboy-promise
Promisified multipart collection using Busboy

Usage

npm install busboy-promise

Assume req is a request object. options is an optional object to pass additional options to Busboy.
var busboyPromise = require('busboy-promise');

busboyPromise(req, options)
  .then(function (parts) {
    for (var name in parts.fields) {
      var field = parts.fields[name];
      console.log('field name:', field.value, 'value:', field.value);
    }

    for (var name in parts.files) {
      var file = parts.files[name];
      console.log('file field name:', file.value);
    }
  })
  .catch(function (err) {
    console.error('error:', err);
  });

parts is an object with two properties:
fields: A hashmap of fields. Property names are the field names. Values are objects with the original Busboy event arguments:
{
  value: /* the value */,
  isNameTruncated: /* whether the name is truncated */,
  isValueTruncated: /* whether the value is truncated */,
  encoding: /* the encoding */,
  mimeType: /* the MIME type */
}

files: A hashmap of files. Property names are the field names. Values are object with the original Busboy event arguments:
{
  file: /* the file stream */,
  filename: /* the original filename */,
  encoding: /* the encoding */,
  mimeType: /* the MIME type */
}