I am writing a file upload demo by multer in node.js.When form submit, I can get the file information, but it does not have path property.
<form method="post" enctype="multipart/form-data">
<p>
<input type="text" name="name" placeholder="name">
</p>
<p>
<input type="file" name="photo">
</p>
<p>
<input type="submit" value="Upload">
</p>
</form>
function (req, res ,next) {
var img = req.file;
var name = req.body.name || img.originalname;
var path = require('path').join(dir, name);
console.log(img);
}
var multer = require('multer')();
app.post('/upload',multer.single('photo'),photos.submit(app.get('photos')));
You are using memStorage for storing file. That's why there is no path in req.file.
Try changing this to: var upload = multer({ dest: 'uploads/' }). Replace uploads/ with directory where you want to upload your file.