OpenVeo server API for plugins

API Docs for: 7.0.0
Show:

MultipartParser

Summary

Defines a multipart parser to parse multipart requests.

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

Constructor

MultipartParser

Syntax

MultipartParser

(
  • request
  • fileFields
  • [limits]
)

Summary

Parameters:

  • request Request

    HTTP Request containing a multipart body, it will be altered with parsing properties

  • fileFields Array

    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
  • [limits] Object optional

    Multipart limits configuration, for more information about available limits see Multer documentation (https://www.npmjs.com/package/multer#limits).

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);
});

Methods

getField

Syntax

getField

(
  • fieldName
)
Object | Null

Summary

Gets fields configuration by name.

Parameters:

  • fieldName String

    The name of the field containing files

Returns:

Object | Null:

The field configuration

getFileName

Syntax

getFileName

(
  • originalFileName
  • fieldName
  • callback
)
async

Summary

Builds final file name.

It avoids collisions with existing files and sanitizes file name.

Parameters:

  • originalFileName String

    The original file name

  • fieldName String

    The name of the field containing the file

  • callback Function

    The function to call when done

    • Error The error if an error occurred, null otherwise
    • String The computed file name

parse

Syntax

parse

(
  • callback
)
async

Summary

Parses multipart content of the request and performs uploads if any.

Parameters:

  • callback Function

    The function to call when done

    • Error The error if an error occurred, null otherwise

Properties

detectedFilesPaths

Syntax

detectedFilesPaths

Array final

Summary

Final paths of files detected in multipart body.

fileFields

Syntax

fileFields

Array final

Summary

The list of file field descriptors.

limits

Syntax

limits

Object final

Summary

Multipart limits configuration.

request

Syntax

request

Request final

Summary

The HTTP request containing a multipart body.