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.
ejs file
<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>
js
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);
}
req.file
via ChenLee
No comments:
Post a Comment