安装 multer
模块
npm install multer --save
简单使用
// test.js
const express = require('express');
const multer = require('multer');
const app = express();
const upload = multer({
dest: 'c:/tmp'
});
// 单个文件的上传
app.post('/upload', upload.single('avator'), (req, res) => {
res.send(req.file);
})
// 多个文件的上传
app.post('/uploadMany', upload.array('photos', 3), (req, res) => {
res.send(req.files);
})
app.listen(3000);
</article>
网友评论