1- # Multer [ ![ Build Status] ( https://badgen.net/github/checks/expressjs/multer/master?label=ci )] ( https://github.com/expressjs/multer/actions/workflows/ci.yml ) [ ![ Test Coverage] ( https://badgen.net/coveralls/c/github/expressjs/multer/master )] ( https://coveralls.io/r/expressjs/multer?branch=master ) [ ![ NPM version ] ( https://badge.fury.io/js/multer.svg )] ( https://badge.fury.io/js/multer ) [ ![ js-standard-style ] ( https://img.shields.io/ badge/code%20style-standard-brightgreen.svg?style=flat )] ( https://github.com/feross/standard )
1+ # Multer [ ![ NPM Version ] [ npm-version-image ]] [ npm-url ] [ ![ NPM Downloads ] [ npm-downloads-image ]] [ npm-url ] [ ![ Build Status] [ ci-image ]] [ ci-url ] [ ![ Test Coverage] [ test-image ]] [ test-url ] [ ![ OpenSSF Scorecard Badge ] [ ossf-scorecard- badge]] [ ossf-scorecard-visualizer ]
22
33Multer is a node.js middleware for handling ` multipart/form-data ` , which is primarily used for uploading files. It is written
44on top of [ busboy] ( https://github.com/mscdex/busboy ) for maximum efficiency.
55
66** NOTE** : Multer will not process any form which is not multipart (` multipart/form-data ` ).
77
8- ## Translations
8+ ## Translations
99
1010This README is also available in other languages:
1111
12+ - [ العربية] ( https://github.com/expressjs/multer/blob/master/doc/README-ar.md ) (Arabic)
1213- [ Español] ( https://github.com/expressjs/multer/blob/master/doc/README-es.md ) (Spanish)
1314- [ 简体中文] ( https://github.com/expressjs/multer/blob/master/doc/README-zh-cn.md ) (Chinese)
1415- [ 한국어] ( https://github.com/expressjs/multer/blob/master/doc/README-ko.md ) (Korean)
1516- [ Русский язык] ( https://github.com/expressjs/multer/blob/master/doc/README-ru.md ) (Russian)
1617- [ Việt Nam] ( https://github.com/expressjs/multer/blob/master/doc/README-vi.md ) (Vietnam)
1718- [ Português] ( https://github.com/expressjs/multer/blob/master/doc/README-pt-br.md ) (Portuguese Brazil)
19+ - [ Français] ( https://github.com/expressjs/multer/blob/master/doc/README-fr.md ) (French)
20+ - [ O'zbek tili] ( https://github.com/expressjs/multer/blob/master/doc/README-uz.md ) (Uzbek)
1821
1922## Installation
2023
@@ -53,8 +56,8 @@ app.post('/photos/upload', upload.array('photos', 12), function (req, res, next)
5356 // req.body will contain the text fields, if there were any
5457})
5558
56- const cpUpload = upload .fields ([{ name: ' avatar' , maxCount: 1 }, { name: ' gallery' , maxCount: 8 }])
57- app .post (' /cool-profile' , cpUpload , function (req , res , next ) {
59+ const uploadMiddleware = upload .fields ([{ name: ' avatar' , maxCount: 1 }, { name: ' gallery' , maxCount: 8 }])
60+ app .post (' /cool-profile' , uploadMiddleware , function (req , res , next ) {
5861 // req.files is an object (String -> Array) where fieldname is the key, and the value is array of files
5962 //
6063 // e.g.
@@ -78,14 +81,14 @@ app.post('/profile', upload.none(), function (req, res, next) {
7881})
7982```
8083
81- Here's an example on how multer is used an HTML form. Take special note of the ` enctype="multipart/form-data" ` and ` name="uploaded_file" ` fields:
84+ Here's an example on how multer is used in a HTML form. Take special note of the ` enctype="multipart/form-data" ` and ` name="uploaded_file" ` fields:
8285
8386``` html
8487<form action =" /stats" enctype =" multipart/form-data" method =" post" >
8588 <div class =" form-group" >
8689 <input type =" file" class =" form-control-file" name =" uploaded_file" >
8790 <input type =" text" class =" form-control" placeholder =" Number of speakers" name =" nspeakers" >
88- <input type =" submit" value =" Get me the stats!" class =" btn btn-default" >
91+ <input type =" submit" value =" Get me the stats!" class =" btn btn-default" >
8992 </div >
9093</form >
9194```
@@ -96,9 +99,9 @@ Then in your javascript file you would add these lines to access both the file a
9699const multer = require (' multer' )
97100const upload = multer ({ dest: ' ./public/data/uploads/' })
98101app .post (' /stats' , upload .single (' uploaded_file' ), function (req , res ) {
99- // req.file is the name of your file in the form above, here 'uploaded_file'
100- // req.body will hold the text fields, if there were any
101- console .log (req .file , req .body )
102+ // req.file is the name of your file in the form above, here 'uploaded_file'
103+ // req.body will hold the text fields, if there were any
104+ console .log (req .file , req .body )
102105});
103106```
104107
@@ -239,7 +242,7 @@ order that the client transmits fields and files to the server.
239242
240243For understanding the calling convention used in the callback (needing to pass
241244null as the first param), refer to
242- [ Node.js error handling] ( https://www.joyent.com/node-js/production/design/errors )
245+ [ Node.js error handling] ( https://web.archive.org/web/20220417042018/https:// www.joyent.com/node-js/production/design/errors )
243246
244247#### ` MemoryStorage `
245248
@@ -331,3 +334,13 @@ For information on how to build your own storage engine, see [Multer Storage Eng
331334## License
332335
333336[ MIT] ( LICENSE )
337+
338+ [ ci-image ] : https://badgen.net/github/checks/expressjs/multer/master?label=ci
339+ [ ci-url ] : https://github.com/expressjs/multer/actions/workflows/ci.yml
340+ [ test-url ] : https://coveralls.io/r/expressjs/multer?branch=master
341+ [ test-image ] : https://badgen.net/coveralls/c/github/expressjs/multer/master
342+ [ npm-downloads-image ] : https://badgen.net/npm/dm/multer
343+ [ npm-url ] : https://npmjs.org/package/multer
344+ [ npm-version-image ] : https://badgen.net/npm/v/multer
345+ [ ossf-scorecard-badge ] : https://api.scorecard.dev/projects/github.com/expressjs/multer/badge
346+ [ ossf-scorecard-visualizer ] : https://ossf.github.io/scorecard-visualizer/#/projects/github.com/expressjs/multer
0 commit comments