<form action="/upload" method="post">
<input type="file" name="avatar" id="avatarinput" onchange="readfichier()">
<button type='submit'>Save</button>
</form>
SERVER
app.post('/upload', upload.single('avatar'), function (req, res, next) {
console.log(req.file);
fs.rename(req.file.path, 'uploads/'+req.file.originalname, function (err) {
if (err) throw err;
console.log('renamed complete');
});
res.end('Success');
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
})
I got this error: TypeError: Cannot read properties of undefined (reading 'path')