Ошибка:
MulterError: Unexpected field...
multer в server.js:
const multer = require('multer');
const upload = multer({ dest: 'upload/' });
const type = upload.single('filedata');
app.post('/profile/:id/user-img', type, async(req, res) => {
try {
const {img} = req.body;
const userFind = await User.findById(req.params.id);
if (!img) {
console.log('Ошибка при загрузке файла');
} else {
console.log('Файл загружен');
await User.updateOne({
img: img
})
res.redirect('/profile/'+userFind);
}
} catch (e) {
console.log(e.message);
}
})
multer в html (pug):
form(action="/profile/"+ user._id +"/user-img" method="POST" enctype="multipart/form-data")
input(type="file" name="img" required)
input(type="submit" value="Load")