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 ]
2
2
3
3
Multer is a node.js middleware for handling ` multipart/form-data ` , which is primarily used for uploading files. It is written
4
4
on top of [ busboy] ( https://github.com/mscdex/busboy ) for maximum efficiency.
5
5
6
6
** NOTE** : Multer will not process any form which is not multipart (` multipart/form-data ` ).
7
7
8
- ## Translations
8
+ ## Translations
9
9
10
10
This README is also available in other languages:
11
11
12
+ - [ العربية] ( https://github.com/expressjs/multer/blob/master/doc/README-ar.md ) (Arabic)
12
13
- [ Español] ( https://github.com/expressjs/multer/blob/master/doc/README-es.md ) (Spanish)
13
14
- [ 简体中文] ( https://github.com/expressjs/multer/blob/master/doc/README-zh-cn.md ) (Chinese)
14
15
- [ 한국어] ( https://github.com/expressjs/multer/blob/master/doc/README-ko.md ) (Korean)
15
16
- [ Русский язык] ( https://github.com/expressjs/multer/blob/master/doc/README-ru.md ) (Russian)
16
17
- [ Việt Nam] ( https://github.com/expressjs/multer/blob/master/doc/README-vi.md ) (Vietnam)
17
18
- [ 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)
18
21
19
22
## Installation
20
23
@@ -53,8 +56,8 @@ app.post('/photos/upload', upload.array('photos', 12), function (req, res, next)
53
56
// req.body will contain the text fields, if there were any
54
57
})
55
58
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 ) {
58
61
// req.files is an object (String -> Array) where fieldname is the key, and the value is array of files
59
62
//
60
63
// e.g.
@@ -78,14 +81,14 @@ app.post('/profile', upload.none(), function (req, res, next) {
78
81
})
79
82
```
80
83
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:
82
85
83
86
``` html
84
87
<form action =" /stats" enctype =" multipart/form-data" method =" post" >
85
88
<div class =" form-group" >
86
89
<input type =" file" class =" form-control-file" name =" uploaded_file" >
87
90
<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" >
89
92
</div >
90
93
</form >
91
94
```
@@ -96,9 +99,9 @@ Then in your javascript file you would add these lines to access both the file a
96
99
const multer = require (' multer' )
97
100
const upload = multer ({ dest: ' ./public/data/uploads/' })
98
101
app .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 )
102
105
});
103
106
```
104
107
@@ -239,7 +242,7 @@ order that the client transmits fields and files to the server.
239
242
240
243
For understanding the calling convention used in the callback (needing to pass
241
244
null 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 )
243
246
244
247
#### ` MemoryStorage `
245
248
@@ -331,3 +334,13 @@ For information on how to build your own storage engine, see [Multer Storage Eng
331
334
## License
332
335
333
336
[ 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