как с клиента принять файл на node js express?
с клиента передается файл excel на сервер node js(express). как на сервере его принять и обработать?
Ответы (1 шт):
Автор решения: nörbörnën
→ Ссылка
Используйте multer - is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files.
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const multer = require('multer');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const upload = multer({
dest: path.join(__dirname, 'uploads')
});
app.get('/', (req, res) => {
res.render('home', { test: 'test' });
});
app.post(
'/send',
upload.fields([{name: 'fileEmailTo'}, {name: 'fileMessageTo'}]),
(req, res) => {
console.log(req.body);
res.status(204).json({});
}
);
app.listen(5000, () => {
console.log('Server has been started at port 5000...');
});