22 <img alt =" npm formidable package logo " src =" https://raw.githubusercontent.com/node-formidable/formidable/master/logo.png " />
33</p >
44
5- # formidable [ ![ npm version] [ npmv-img ]] [ npmv-url ] [ ![ MIT license] [ license-img ]] [ license-url ] [ ![ Libera Manifesto] [ libera-manifesto-img ]] [ libera-manifesto-url ] [ ![ Twitter ] [ twitter-img ]] [ twitter-url ]
5+ # formidable [ ![ npm version] [ npmv-img ]] [ npmv-url ] [ ![ MIT license] [ license-img ]] [ license-url ] [ ![ Libera Manifesto] [ libera-manifesto-img ]] [ libera-manifesto-url ]
66
77> A Node.js module for parsing form data, especially file uploads.
88
9+ > [ !CAUTION] As of April 2025, old versions like v1 and v2 are still the most
10+ > used, while they are deperecated for years -- they are also vulnerable to
11+ > attacks if you are not implementing it properly. ** Please upgrade!** We are
12+ > here to help, and AI Editors & Agents could help a lot in such codemod-like
13+ > migrations.
14+
15+ > [ !TIP] If you are starting a fresh project, try ` formidable@latest ` (v3) or
16+ > you can check out the ` formidable-mini ` which is a super minimal version of
17+ > Formidable (not quite configurable yet, but when it does it could become the
18+ > basis for ` formidable@v4 ` ), using web standards like FormData API and File
19+ > API, and you can use it to stream uploads directly to S3 or other such
20+ > services.
21+
922[ ![ Code style] [ codestyle-img ]] [ codestyle-url ]
10- [ ![ codecoverage] [ codecov-img ]] [ codecov-url ]
1123[ ![ linux build status] [ linux-build-img ]] [ build-url ]
12- [ ![ windows build status] [ windows-build-img ]] [ build-url ]
1324[ ![ macos build status] [ macos-build-img ]] [ build-url ]
1425
1526If you have any _ how-to_ kind of questions, please read the [ Contributing
1627Guide] [ contributing-url ] and [ Code of Conduct] [ code_of_conduct-url ]
1728documents.<br /> For bugs reports and feature requests, [ please create an
18- issue] [ open-issue-url ] or ping [ @ tunnckoCore / @ 3a1FcBx0 ] ( https://twitter.com/3a1FcBx0 )
19- at Twitter.
29+ issue] [ open-issue-url ] or ping
30+ [ @wgw_eth / @wgw_lol ] ( https://twitter.com/wgw_eth ) at Twitter.
2031
2132[ ![ Conventional Commits] [ ccommits-img ]] [ ccommits-url ]
2233[ ![ Minimum Required Nodejs] [ nodejs-img ]] [ npmv-url ]
34+ [ ![ Buy me a Kofi] [ kofi-img ]] [ kofi-url ]
35+ [ ![ Make A Pull Request] [ prs-welcome-img ]] [ prs-welcome-url ]
36+ [ ![ Twitter] [ twitter-img ]] [ twitter-url ]
37+
38+ <!-- [![Conventional Commits][ccommits-img]][ccommits-url]
39+ [![Minimum Required Nodejs][nodejs-img]][npmv-url]
2340[![Tidelift Subcsription][tidelift-img]][tidelift-url]
2441[![Buy me a Kofi][kofi-img]][kofi-url]
2542[![Renovate App Status][renovateapp-img]][renovateapp-url]
26- [ ![ Make A Pull Request] [ prs-welcome-img ]] [ prs-welcome-url ]
43+ [![Make A Pull Request][prs-welcome-img]][prs-welcome-url] -->
2744
28- This project is [ semantically versioned] ( https://semver.org ) and available as
45+ <!-- This project is [semantically versioned](https://semver.org) and available as
2946part of the [Tidelift Subscription][tidelift-url] for professional grade
3047assurances, enhanced support and security.
3148[Learn more.](https://tidelift.com/subscription/pkg/npm-formidable?utm_source=npm-formidable&utm_medium=referral&utm_campaign=enterprise)
@@ -34,14 +51,16 @@ _The maintainers of `formidable` and thousands of other packages are working
3451with Tidelift to deliver commercial support and maintenance for the Open Source
3552dependencies you use to build your applications. Save time, reduce risk, and
3653improve code health, while paying the maintainers of the exact dependencies you
37- use._
54+ use._ -->
3855
3956[ ![ ] [ npm-weekly-img ]] [ npmv-url ] [ ![ ] [ npm-monthly-img ]] [ npmv-url ]
4057[ ![ ] [ npm-yearly-img ]] [ npmv-url ] [ ![ ] [ npm-alltime-img ]] [ npmv-url ]
4158
4259## Project Status: Maintained
4360
44- _ Check [ VERSION NOTES] ( https://github.com/node-formidable/formidable/blob/master/VERSION_NOTES.md ) for more information on v1, v2, and v3 plans, NPM dist-tags and branches._
61+ _ Check
62+ [ VERSION NOTES] ( https://github.com/node-formidable/formidable/blob/master/VERSION_NOTES.md )
63+ for more information on v1, v2, and v3 plans, NPM dist-tags and branches._
4564
4665This module was initially developed by
4766[ ** @felixge ** ] ( https://github.com/felixge ) for
@@ -73,7 +92,9 @@ This project requires `Node.js >= 10.13`. Install it using
7392recommend to use Yarn when you think to contribute to this project._
7493
7594This is a low-level package, and if you're using a high-level framework it _ may_
76- already be included. Check the examples below and the [ examples/] ( https://github.com/node-formidable/formidable/tree/master/examples ) folder.
95+ already be included. Check the examples below and the
96+ [ examples/] ( https://github.com/node-formidable/formidable/tree/master/examples )
97+ folder.
7798
7899``` sh
79100# v2
@@ -85,8 +106,8 @@ npm install formidable@v2
85106npm install formidable@v3
86107```
87108
88- _ ** Note:** In near future v3 will be published on the ` latest ` NPM dist-tag. Future not ready releases will continue to be published on ` canary ` dist-tag. _
89-
109+ _ ** Note:** In near future v3 will be published on the ` latest ` NPM dist-tag.
110+ Future not ready releases will continue to be published on ` canary ` dist-tag. _
90111
91112## Examples
92113
@@ -325,12 +346,13 @@ See it's defaults in [src/Formidable.js DEFAULT_OPTIONS](./src/Formidable.js)
325346 uploaded file.
326347- ` options.maxFileSize ` ** {number}** - default ` 200 * 1024 * 1024 ` (200mb);
327348 limit the size of uploaded file.
328- - ` options.maxFields ` ** {number}** - default ` 1000 ` ; limit the number of fields, set 0 for unlimited
349+ - ` options.maxFields ` ** {number}** - default ` 1000 ` ; limit the number of fields,
350+ set 0 for unlimited
329351- ` options.maxFieldsSize ` ** {number}** - default ` 20 * 1024 * 1024 ` (20mb);
330352 limit the amount of memory all fields together (except files) can allocate in
331353 bytes.
332- - ` options.hashAlgorithm ` ** {string | false}** - default ` false ` ; include checksums calculated
333- for incoming files, set this to some hash algorithm, see
354+ - ` options.hashAlgorithm ` ** {string | false}** - default ` false ` ; include
355+ checksums calculated for incoming files, set this to some hash algorithm, see
334356 [ crypto.createHash] ( https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options )
335357 for available algorithms
336358- ` options.fileWriteStreamHandler ` ** {function}** - default ` null ` , which by
@@ -354,8 +376,7 @@ See it's defaults in [src/Formidable.js DEFAULT_OPTIONS](./src/Formidable.js)
354376- ` options.filter ` ** {function}** - default function that always returns true.
355377 Use it to filter files before they are uploaded. Must return a boolean.
356378
357-
358- #### ` options.filename ` ** {function}** function (name, ext, part, form) -> string
379+ #### ` options.filename ` ** {function}** function (name, ext, part, form) -> string
359380
360381_ ** Note:** If this size of combined fields, or size of some file is exceeded, an
361382` 'error' ` event is fired._
@@ -370,20 +391,19 @@ form.bytesReceived;
370391form .bytesExpected ;
371392```
372393
373- #### ` options.filter ` ** {function}** function ({name, originalFilename, mimetype}) -> boolean
394+ #### ` options.filter ` ** {function}** function ({name, originalFilename, mimetype}) -> boolean
374395
375- ** Note:** use an outside variable to cancel all uploads upon the first error
396+ ** Note:** use an outside variable to cancel all uploads upon the first error
376397
377398``` js
378399const options = {
379- filter : function ({name, originalFilename, mimetype}) {
400+ filter : function ({ name, originalFilename, mimetype }) {
380401 // keep only images
381- return mimetype && mimetype .includes (" image" );
382- }
402+ return mimetype && mimetype .includes (' image' );
403+ },
383404};
384405```
385406
386-
387407### .parse(request, callback)
388408
389409Parses an incoming Node.js ` request ` containing form data. If ` callback ` is
@@ -405,41 +425,41 @@ multipart stream. Doing so will disable any `'field'` / `'file'` events
405425processing which would occur otherwise, making you fully responsible for
406426handling the processing.
407427
408- About ` uploadDir ` , given the following directory structure
428+ About ` uploadDir ` , given the following directory structure
429+
409430```
410431project-name
411432├── src
412433│ └── server.js
413- │
434+ │
414435└── uploads
415436 └── image.jpg
416437```
417438
418439` __dirname ` would be the same directory as the source file itself (src)
419440
420-
421441``` js
422- ` ${ __dirname } /../uploads`
442+ ` ${ __dirname } /../uploads` ;
423443```
424444
425445to put files in uploads.
426446
427- Omitting ` __dirname ` would make the path relative to the current working directory. This would be the same if server.js is launched from src but not project-name.
428-
447+ Omitting ` __dirname ` would make the path relative to the current working
448+ directory. This would be the same if server.js is launched from src but not
449+ project-name.
429450
430451` null ` will use default which is ` os.tmpdir() `
431452
432- Note: If the directory does not exist, the uploaded files are __ silently discarded__ . To make sure it exists:
453+ Note: If the directory does not exist, the uploaded files are ** silently
454+ discarded** . To make sure it exists:
433455
434456``` js
435- import {createNecessaryDirectoriesSync } from " filesac" ;
436-
457+ import { createNecessaryDirectoriesSync } from ' filesac' ;
437458
438459const uploadPath = ` ${ __dirname } /../uploads` ;
439460createNecessaryDirectoriesSync (` ${ uploadPath} /x` );
440461```
441462
442-
443463In the example below, we listen on couple of events and direct them to the
444464` data ` listener, so you can do whatever you choose there, based on whether its
445465before the file been emitted, the header value, the header name, on field, on
@@ -468,30 +488,33 @@ form.once('end', () => {
468488});
469489
470490// If you want to customize whatever you want...
471- form .on (' data' , ({ name, key, value, buffer, start, end, formname, ... more }) => {
472- if (name === ' partBegin' ) {
473- }
474- if (name === ' partData' ) {
475- }
476- if (name === ' headerField' ) {
477- }
478- if (name === ' headerValue' ) {
479- }
480- if (name === ' headerEnd' ) {
481- }
482- if (name === ' headersEnd' ) {
483- }
484- if (name === ' field' ) {
485- console .log (' field name:' , key);
486- console .log (' field value:' , value);
487- }
488- if (name === ' file' ) {
489- console .log (' file:' , formname, value);
490- }
491- if (name === ' fileBegin' ) {
492- console .log (' fileBegin:' , formname, value);
493- }
494- });
491+ form .on (
492+ ' data' ,
493+ ({ name, key, value, buffer, start, end, formname, ... more }) => {
494+ if (name === ' partBegin' ) {
495+ }
496+ if (name === ' partData' ) {
497+ }
498+ if (name === ' headerField' ) {
499+ }
500+ if (name === ' headerValue' ) {
501+ }
502+ if (name === ' headerEnd' ) {
503+ }
504+ if (name === ' headersEnd' ) {
505+ }
506+ if (name === ' field' ) {
507+ console .log (' field name:' , key);
508+ console .log (' field value:' , value);
509+ }
510+ if (name === ' file' ) {
511+ console .log (' file:' , formname, value);
512+ }
513+ if (name === ' fileBegin' ) {
514+ console .log (' fileBegin:' , formname, value);
515+ }
516+ },
517+ );
495518```
496519
497520### .use(plugin: Plugin)
@@ -603,7 +626,7 @@ export interface File {
603626
604627 // The name this file had according to the uploading client.
605628 file .originalFilename : string | null ;
606-
629+
607630 // calculated based on options provided
608631 file .newFilename : string | null ;
609632
@@ -653,12 +676,12 @@ file system.
653676
654677``` js
655678form .on (' fileBegin' , (formName , file ) => {
656- // accessible here
657- // formName the name in the form (<input name="thisname" type="file">) or http filename for octetstream
658- // file.originalFilename http filename or null if there was a parsing error
659- // file.newFilename generated hexoid or what options.filename returned
660- // file.filepath default pathnme as per options.uploadDir and options.filename
661- // file.filepath = CUSTOM_PATH // to change the final path
679+ // accessible here
680+ // formName the name in the form (<input name="thisname" type="file">) or http filename for octetstream
681+ // file.originalFilename http filename or null if there was a parsing error
682+ // file.newFilename generated hexoid or what options.filename returned
683+ // file.filepath default pathnme as per options.uploadDir and options.filename
684+ // file.filepath = CUSTOM_PATH // to change the final path
662685});
663686```
664687
@@ -669,9 +692,9 @@ Emitted whenever a field / file pair has been received. `file` is an instance of
669692
670693``` js
671694form .on (' file' , (formname , file ) => {
672- // same as fileBegin, except
673- // it is too late to change file.filepath
674- // file.hash is available if options.hash was used
695+ // same as fileBegin, except
696+ // it is too late to change file.filepath
697+ // file.hash is available if options.hash was used
675698});
676699```
677700
@@ -766,8 +789,10 @@ Thanks goes to these wonderful people
766789From a [ Felix blog post] ( https://felixge.de/2013/03/11/the-pull-request-hack/ ) :
767790
768791- [ Sven Lito] ( https://github.com/svnlto ) for fixing bugs and merging patches
769- - [ egirshov] ( https://github.com/egirshov ) for contributing many improvements to the node-formidable multipart parser
770- - [ Andrew Kelley] ( https://github.com/superjoe30 ) for also helping with fixing bugs and making improvements
792+ - [ egirshov] ( https://github.com/egirshov ) for contributing many improvements to
793+ the node-formidable multipart parser
794+ - [ Andrew Kelley] ( https://github.com/superjoe30 ) for also helping with fixing
795+ bugs and making improvements
771796- [ Mike Frey] ( https://github.com/mikefrey ) for contributing JSON support
772797
773798## License
@@ -795,8 +820,8 @@ Formidable is licensed under the [MIT License][license-url].
795820[ renovateapp-img ] : https://badgen.net/badge/renovate/enabled/green?cache=300
796821[ prs-welcome-img ] : https://badgen.net/badge/PRs/welcome/green?cache=300
797822[ prs-welcome-url ] : http://makeapullrequest.com
798- [ twitter-url ] : https://twitter.com/3a1fcBx0
799- [ twitter-img ] : https://badgen.net/twitter/follow/3a1fcBx0 ?icon=twitter&color=1da1f2&cache=300
823+ [ twitter-url ] : https://twitter.com/wgw_eth
824+ [ twitter-img ] : https://badgen.net/badge/ twitter/follow/wgw_eth ?icon=twitter&color=1da1f2&cache=30
800825
801826[ npm-weekly-img ] : https://badgen.net/npm/dw/formidable?icon=npm&cache=300
802827[ npm-monthly-img ] : https://badgen.net/npm/dm/formidable?icon=npm&cache=300
@@ -819,8 +844,8 @@ Formidable is licensed under the [MIT License][license-url].
819844[ kofi-url ] : https://ko-fi.com/tunnckoCore/commissions
820845[ kofi-img ] : https://badgen.net/badge/ko-fi/support/29abe0c2?cache=300&icon=https://rawcdn.githack.com/tunnckoCore/badgen-icons/f8264c6414e0bec449dd86f2241d50a9b89a1203/icons/kofi.svg
821846
822- [ linux-build-img ] : https://badgen.net/github/checks/node-formidable/formidable/master/ubuntu?cache=300& label=linux%20build&icon=github
823- [ macos-build-img ] : https://badgen.net/github/checks/node-formidable/formidable/master/macos?cache=300& label=macos%20build&icon=github
847+ [ linux-build-img ] : https://badgen.net/github/checks/node-formidable/formidable/master? label=linux%20build&icon=github
848+ [ macos-build-img ] : https://badgen.net/github/checks/node-formidable/formidable/master? label=macos%20build&icon=github
824849[ windows-build-img ] : https://badgen.net/github/checks/node-formidable/formidable/master/windows?cache=300&label=windows%20build&icon=github
825- [ build-url ] : https://github.com/node-formidable/formidable/actions?query=workflow%3Anodejs
850+ [ build-url ] : https://github.com/node-formidable/formidable/actions
826851<!-- prettier-ignore-end -->
0 commit comments