lib/multipart/MultipartParser.js
function MultipartParser(request, fileFields, limits) {
  Object.defineProperties(this, {

    /**
     * The HTTP request containing a multipart body.
     *
     * @property request
     * @type Request
     * @final
     */
    request: {value: request},

    /**
     * The list of file field descriptors.
     *
     * @property fileFields
     * @type Array
     * @final
     */
    fileFields: {value: fileFields || []},

    /**
     * Multipart limits configuration.
     *
     * @property limits
     * @type Object
     * @final
     */
    limits: {value: limits},

    /**
     * Final paths of files detected in multipart body.
     *
     * @property detectedFilesPaths
     * @type Array
     * @final
     */
    detectedFilesPaths: {value: []}

  });

  if (!this.request)
    throw new TypeError('A MultipartParser needs a request');
}
function MultipartParser(request, fileFields, limits) {
  Object.defineProperties(this, {

    /**
     * The HTTP request containing a multipart body.
     *
     * @property request
     * @type Request
     * @final
     */
    request: {value: request},

    /**
     * The list of file field descriptors.
     *
     * @property fileFields
     * @type Array
     * @final
     */
    fileFields: {value: fileFields || []},

    /**
     * Multipart limits configuration.
     *
     * @property limits
     * @type Object
     * @final
     */
    limits: {value: limits},

    /**
     * Final paths of files detected in multipart body.
     *
     * @property detectedFilesPaths
     * @type Array
     * @final
     */
    detectedFilesPaths: {value: []}

  });

  if (!this.request)
    throw new TypeError('A MultipartParser needs a request');
}
function MultipartParser ( request , fileFields , limits ) { Object . defineProperties ( this , { /**
     * The HTTP request containing a multipart body.
     *
     * @property request
     * @type Request
     * @final
     */ request : { value : request } , /**
     * The list of file field descriptors.
     *
     * @property fileFields
     * @type Array
     * @final
     */ fileFields : { value : fileFields || [ ] } , /**
     * Multipart limits configuration.
     *
     * @property limits
     * @type Object
     * @final
     */ limits : { value : limits } , /**
     * Final paths of files detected in multipart body.
     *
     * @property detectedFilesPaths
     * @type Array
     * @final
     */ detectedFilesPaths : { value : [ ] } } ) ; if ( ! this . request ) throw new TypeError ( 'A MultipartParser needs a request' ) ; }
Defines a multipart parser to parse multipart requests.

Use MultipartParser to get fields from multipart requests (including files).

@example

// Get multipart parser
var MultipartParser = require('@openveo/api').multipart.MultipartParser;

// Create a request parser expecting several files: files in photos "field" and a file in "videos" field
var parser = new MultipartParser(request, [
{
name: 'photos',
destinationPath: '/tmp/photos',
maxCount: 2,
unique: true
},
{
name: 'videos',
destinationPath: '/tmp/videos',
maxCount: 1,
unique: false
}
], {
fieldNameSize: 100,
fieldSize: 1024,
fields: Infinity,
fileSize: Infinity,
files: Infinity,
parts: Infinity,
headerPairs: 2000
});

parser.parse(function(error) {
if (error)
console.log('Something went wrong when uploading');
else
console.log(request.files);
});

@class MultipartParser
@constructor
@param {Request} request HTTP Request containing a multipart body, it will be altered with parsing properties
@param {Array} fileFields A list of file field descriptors with:
- {String} name The field name which contains the file
- {String} destinationPath The destination directory where the file will be uploaded
- {Number} [maxCount] The maximum number of files allowed for this field
- {Boolean} [unique] true to generate unique file names for files corresponding to this field, false to generate a
unique id only if a file with the same name already exists in the destination folder
@param {Object} [limits] Multipart limits configuration, for more information about
available limits see Multer documentation (https://www.npmjs.com/package/multer#limits).
@throws {TypeError} If request is not as expected
Defines a multipart parser to parse multipart requests .