(Multer NPM) has already written there in documentation:
.single(fieldname) ????=> (req.file)
Accept a single file with the name fieldname. The single file will be stored in req.file.
app.post('/upload', upload.single('file'), (req, res, next) => {
console.log('Uploaded!');
res.send(req.file);
});
.array(fieldname[, maxCount]) ????=> (req.files)
Accept an array of files, all with the name fieldname. Optionally error out if more than maxCount files are uploaded. The array of files will be stored in req.files.
app.post('/upload', upload.array('file', 1), (req, res, next) => {
console.log('Uploaded!');
res.send(req.files);
});
.fields(fields) ????=> (req.files)
Accept a mix of files, specified by fields. An object with arrays of files will be stored in req.files
app.post('/upload', upload.fields([
{ name: 'avatar', maxCount: 1 },
{ name: 'gallery', maxCount: 8 }
]), (req, res, next) => {
console.log('Uploaded!');
res.send(req.files);
});
.any() ????=> (req.files)
Accepts all files that comes over the wire. An array of files will be stored in req.files.
.none()
Accept only text fields. If any file upload is made, error with code "LIMIT_UNEXPECTED_FILE" will be issued.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…