Gathering detailed insights and metrics for multiparty
Gathering detailed insights and metrics for multiparty
Gathering detailed insights and metrics for multiparty
Gathering detailed insights and metrics for multiparty
A node.js module for parsing multipart-form data requests which supports streams2
npm install multiparty
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.1
Supply Chain
99.5
Quality
79
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
206,772,510
Last Day
38,555
Last Week
555,107
Last Month
2,459,133
Last Year
29,003,430
MIT License
1,298 Stars
708 Commits
168 Forks
35 Watchers
8 Branches
65 Contributors
Updated on Jun 16, 2025
Minified
Minified + Gzipped
Latest Version
4.2.3
Package Id
multiparty@4.2.3
Unpacked Size
38.68 kB
Size
12.16 kB
File Count
5
NPM Version
8.1.2
Node Version
16.13.1
Cumulative downloads
Total Downloads
3
Parse http requests with content-type multipart/form-data
, also known as file uploads.
See also busboy - a faster alternative which may be worth looking into.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
npm install multiparty
Parse an incoming multipart/form-data
request.
1var multiparty = require('multiparty'); 2var http = require('http'); 3var util = require('util'); 4 5http.createServer(function(req, res) { 6 if (req.url === '/upload' && req.method === 'POST') { 7 // parse a file upload 8 var form = new multiparty.Form(); 9 10 form.parse(req, function(err, fields, files) { 11 res.writeHead(200, { 'content-type': 'text/plain' }); 12 res.write('received upload:\n\n'); 13 res.end(util.inspect({ fields: fields, files: files })); 14 }); 15 16 return; 17 } 18 19 // show a file upload form 20 res.writeHead(200, { 'content-type': 'text/html' }); 21 res.end( 22 '<form action="/upload" enctype="multipart/form-data" method="post">'+ 23 '<input type="text" name="title"><br>'+ 24 '<input type="file" name="upload" multiple="multiple"><br>'+ 25 '<input type="submit" value="Upload">'+ 26 '</form>' 27 ); 28}).listen(8080);
1var form = new multiparty.Form(options)
Creates a new form. Options:
encoding
- sets encoding for the incoming form fields. Defaults to utf8
.maxFieldsSize
- Limits the amount of memory all fields (not files) can
allocate in bytes. If this value is exceeded, an error
event is emitted.
The default size is 2MB.maxFields
- Limits the number of fields that will be parsed before
emitting an error
event. A file counts as a field in this case.
Defaults to 1000.maxFilesSize
- Only relevant when autoFiles
is true
. Limits the
total bytes accepted for all files combined. If this value is exceeded,
an error
event is emitted. The default is Infinity
.autoFields
- Enables field
events and disables part
events for fields.
This is automatically set to true
if you add a field
listener.autoFiles
- Enables file
events and disables part
events for files.
This is automatically set to true
if you add a file
listener.uploadDir
- Only relevant when autoFiles
is true
. The directory for
placing file uploads in. You can move them later using fs.rename()
.
Defaults to os.tmpdir()
.Parses an incoming node.js request
containing form data.This will cause
form
to emit events based off the incoming request.
1var count = 0; 2var form = new multiparty.Form(); 3 4// Errors may be emitted 5// Note that if you are listening to 'part' events, the same error may be 6// emitted from the `form` and the `part`. 7form.on('error', function(err) { 8 console.log('Error parsing form: ' + err.stack); 9}); 10 11// Parts are emitted when parsing the form 12form.on('part', function(part) { 13 // You *must* act on the part by reading it 14 // NOTE: if you want to ignore it, just call "part.resume()" 15 16 if (part.filename === undefined) { 17 // filename is not defined when this is a field and not a file 18 console.log('got field named ' + part.name); 19 // ignore field's content 20 part.resume(); 21 } 22 23 if (part.filename !== undefined) { 24 // filename is defined when this is a file 25 count++; 26 console.log('got file named ' + part.name); 27 // ignore file's content here 28 part.resume(); 29 } 30 31 part.on('error', function(err) { 32 // decide what to do 33 }); 34}); 35 36// Close emitted after form parsed 37form.on('close', function() { 38 console.log('Upload completed!'); 39 res.setHeader('text/plain'); 40 res.end('Received ' + count + ' files'); 41}); 42 43// Parse req 44form.parse(req);
If cb
is provided, autoFields
and autoFiles
are set to true
and all
fields and files are collected and passed to the callback, removing the need to
listen to any events on form
. This is for convenience when you want to read
everything, but be sure to write cleanup code, as this will write all uploaded
files to the disk, even ones you may not be interested in.
1form.parse(req, function(err, fields, files) { 2 Object.keys(fields).forEach(function(name) { 3 console.log('got field named ' + name); 4 }); 5 6 Object.keys(files).forEach(function(name) { 7 console.log('got file named ' + name); 8 }); 9 10 console.log('Upload completed!'); 11 res.setHeader('text/plain'); 12 res.end('Received ' + files.length + ' files'); 13});
fields
is an object where the property names are field names and the values
are arrays of field values.
files
is an object where the property names are field names and the values
are arrays of file objects.
The amount of bytes received for this form so far.
The expected number of bytes in this form.
Unless you supply a callback to form.parse
, you definitely want to handle
this event. Otherwise your server will crash when users submit bogus
multipart requests!
Only one 'error' event can ever be emitted, and if an 'error' event is emitted, then 'close' will not be emitted.
If the error would correspond to a certain HTTP response code, the err
object
will have a statusCode
property with the value of the suggested HTTP response
code to send back.
Note that an 'error' event will be emitted both from the form
and from the
current part
.
Emitted when a part is encountered in the request. part
is a
ReadableStream
. It also has the following properties:
headers
- the headers for this part. For example, you may be interested
in content-type
.name
- the field name for this partfilename
- only if the part is an incoming filebyteOffset
- the byte offset of this part in the request bodybyteCount
- assuming that this is the last part in the request,
this is the size of this part in bytes. You could use this, for
example, to set the Content-Length
header if uploading to S3.
If the part had a Content-Length
header then that value is used
here instead.Parts for fields are not emitted when autoFields
is on, and likewise parts
for files are not emitted when autoFiles
is on.
part
emits 'error' events! Make sure you handle them.
Emitted when the request is aborted. This event will be followed shortly
by an error
event. In practice you do not need to handle this event.
Emitted when a chunk of data is received for the form. The bytesReceived
argument contains the total count of bytes received for this form so far. The
bytesExpected
argument contains the total expected bytes if known, otherwise
null
.
Emitted after all parts have been parsed and emitted. Not emitted if an error
event is emitted.
If you have autoFiles
on, this is not fired until all the data has been
flushed to disk and the file handles have been closed.
This is typically when you would send your response.
By default multiparty will not touch your hard drive. But if you add this
listener, multiparty automatically sets form.autoFiles
to true
and will
stream uploads to disk for you.
The max bytes accepted per request can be specified with maxFilesSize
.
name
- the field name for this filefile
- an object with these properties:
fieldName
- same as name
- the field name for this fileoriginalFilename
- the filename that the user reports for the filepath
- the absolute path of the uploaded file on diskheaders
- the HTTP headers that were sent along with this filesize
- size of the file in bytesname
- field namevalue
- string field valueNo vulnerabilities found.
Reason
no binaries found in the repo
Reason
25 different organizations found -- score normalized to 10
Details
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no vulnerabilities detected
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
0 out of 1 merged PRs checked by a CI test -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
found 29 unreviewed changesets out of 30 -- score normalized to 0
Reason
no update tool detected
Details
Reason
project is not fuzzed
Details
Reason
0 commit(s) out of 30 and 0 issue activity out of 30 found in the last 90 days -- score normalized to 0
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Score
Last Scanned on 2024-11-11T21:28:06Z
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
-6.6%
38,555
Compared to previous day
Last Week
-4%
555,107
Compared to previous week
Last Month
-2%
2,459,133
Compared to previous month
Last Year
24.9%
29,003,430
Compared to previous year