Constructor
new MultipartParser(request, fileFields, limitsopt)
Defines a multipart parser to parse multipart requests.
Use MultipartParser to get fields from multipart requests (including files).
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object | HTTP Request containing a multipart body, it will be altered with parsing properties |
|||||||||||||||||||||
fileFields |
Array | A list of file field descriptors with: Properties
|
|||||||||||||||||||||
limits |
Object |
<optional> |
Multipart limits configuration, for more information about available limits see Multer documentation. |
- Source:
Throws:
-
If request is not as expected
- Type
- TypeError
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);
});
Members
(readonly) detectedFilesPaths :Array
Final paths of files detected in multipart body.
Type:
- Array
- Source:
(readonly) fileFields :Array
The list of file field descriptors.
Type:
- Array
- Source:
(readonly) limits :Object
Multipart limits configuration.
Type:
- Object
- Source:
(readonly) request :Object
The HTTP request containing a multipart body.
Type:
- Object
- Source:
Methods
getField(fieldName) → {Object|null}
Gets fields configuration by name.
Parameters:
Name | Type | Description |
---|---|---|
fieldName |
String | The name of the field containing files |
- Source:
Returns:
The field configuration
- Type
- Object | null
getFileName(originalFileName, fieldName, callback)
Builds final file name.
It avoids collisions with existing files and sanitizes file name.
Parameters:
Name | Type | Description |
---|---|---|
originalFileName |
String | The original file name |
fieldName |
String | The name of the field containing the file |
callback |
module:multipart/MultipartParser~MultipartParser~getFileNameCallback | The function to call when done |
- Source:
parse(callback)
Parses multipart content of the request and performs uploads if any.
Parameters:
Name | Type | Description |
---|---|---|
callback |
callback | The function to call when done |
- Source:
Type Definitions
getFileNameCallback(error, fileName)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
fileName |
String | Undefined | The computed file name |
- Source: