Wednesday, 3 May 2017

Node.js uploaded file does not have path property

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

enter image description here



via ChenLee

No comments:

Post a Comment