Socket
Socket
Sign inDemoInstall

multer

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multer - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

lab/images/6b384ce3a4b1e2627248b1ca0779e971.png

18

index.js

@@ -28,2 +28,3 @@ var os = require('os');

return function(req, res, next) {
req.body = req.body || {};

@@ -37,3 +38,6 @@ req.files = req.files || {};

var busboy = new Busboy({ headers: req.headers });
// add the request headers to the options
options.headers = req.headers;
var busboy = new Busboy(options);

@@ -93,2 +97,14 @@ // handle text field data

busboy.on('partsLimit', function() {
if (options.onPartsLimit) { options.onPartsLimit(); }
});
busboy.on('filesLimit', function() {
if (options.onFilesLimit) { options.onFilesLimit(); }
});
busboy.on('fieldsLimit', function() {
if (options.onFieldsLimit) { options.onFieldsLimit(); }
});
busboy.on('end', function() {

@@ -95,0 +111,0 @@ // when done parsing the form, pass the control to the next middleware in stack

@@ -32,2 +32,5 @@

console.log('COMPLETED!');
},
limits: {
files: 5
}

@@ -34,0 +37,0 @@ }));

2

package.json
{
"name": "multer",
"version": "0.0.3",
"version": "0.0.4",
"description": "Connect middleware for handling multipart/form-data",

@@ -5,0 +5,0 @@ "main": "index.js",

Multer
======
Multer is a Connect middleware for handling **multipart/form-data**. It can be used with both Connect and Express, seamlessly. It is based on [busboy](https://github.com/mscdex/busboy).
Multer is a Connect / Express middleware for handling **multipart/form-data**. It is written on top of [busboy](https://github.com/mscdex/busboy) for maximum efficiency.

@@ -19,4 +19,9 @@ ## Usage

**IMPORTANT**: Multer will not process any form which not **multipart/form-data** submitted via the **POST** method.
You can access the fields and files in the `request` object:
console.log(req.body);
console.log(req.files);
**IMPORTANT**: Multer will not process any form which is not **multipart/form-data** submitted via the **POST** method.
## Multer file object

@@ -36,3 +41,3 @@

Multer accepts an options object, the most basic of which is the `dest` property, which tells Multer where to upload the files to. In case you omit the options object, the file will be renamed and uploaded to the temporary directory of the system.
Multer accepts an options object, the most basic of which is the `dest` property, which tells Multer where to upload the files. In case you omit the options object, the file will be renamed and uploaded to the temporary directory of the system.

@@ -43,11 +48,17 @@ By the default, Multer will rename the files so as to avoid name conflicts. The renaming function can be customized according to your needs.

1. `dest`
2. `rename(fieldname, filename)`
3. `onFileUploadStart(file)`
4. `onFileUploadData(file, data)`
5. `onFileUploadComplete(file)`
6. `onParseStart()`
7. `onParseEnd()`
8. `onError()`
* `dest`
* `limits`
* `rename(fieldname, filename)`
* `onFileUploadStart(file)`
* `onFileUploadData(file, data)`
* `onFileUploadComplete(file)`
* `onParseStart()`
* `onParseEnd()`
* `onError()`
* `onFilesLimit()`
* `onFieldsLimit()`
* `onPartsLimit()`
Apart from these, Multer also supports more advanced [busboy options](https://github.com/mscdex/busboy#busboy-methods) like `highWaterMark`, `fileHwm`, and `defCharset`.
In an average web app, only `dest` and `rename` might be required, and configured as shown in the example.

@@ -72,2 +83,24 @@

###limits
An object specifying the size limits of the following optional properties.
* `fieldNameSize` - integer - Max field name size (Default: 100 bytes)
* `fieldSize` - integer - Max field value size (Default: 1MB)
* `fields` - integer - Max number of non-file fields (Default: Infinity)
* `fileSize` - integer - For multipart forms, the max file size (Default: Infinity)
* `files` - integer - For multipart forms, the max number of file fields (Default: Infinity)
* `parts` - integer - For multipart forms, the max number of parts (fields + files) (Default: Infinity)
* `headerPairs` - integer - For multipart forms, the max number of header key=>value pairs to parse Default: 2000 (same as node's http).
Example:
limits: {
fieldNameSize: 100,
files: 2,
fields: 5
}
Specifying the limits can help protect your site against denial of service (DoS) attacks.
###rename(fieldname, filename)

@@ -144,2 +177,32 @@

###onFilesLimit()
Event handler triggered when the number of files exceed the specification in the `limit` object. No more files will be parsed after the limit is reached.
Example:
onFilesLimit = function() {
console.log('Crossed file limit!');
};
###onFieldsLimit()
Event handler triggered when the number of fields exceed the specification in the `limit` object. No more fields will be parsed after the limit is reached.
Example:
onFilesLimit = function() {
console.log('Crossed fields limit!');
};
###onPartsLimit()
Event handler triggered when the number of parts exceed the specification in the `limit` object. No more files or fields will be parsed after the limit is reached.
Example:
onFilesLimit = function() {
console.log('Crossed parts limit!');
};
## License (MIT)

@@ -146,0 +209,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc