无法读取属性' fileSize' undefined(req.file)(multer)

时间:2017-04-08 15:28:55

标签: javascript node.js express multer

CODE:

var upload = multer({dest:"./uploads"});

app.post("/", upload.single("file"), function (req, res, next) {
    res.send(req.file.fileSize+"bytes");                     
});

EJS文件:

    <h1>Get the File Size of your Upload !</h1>

<form enctype="multipart/form-data" method="post" action="/" name="file">
    <input type="file" class="form-control">
    <button type = "submit" class = "btn btn-default">Submit</button>
</form>

问题:

我做错了什么?

1 个答案:

答案 0 :(得分:1)

添加姓名=&#39;文件&#39;输入

<h1>Get the File Size of your Upload !</h1>

<form enctype="multipart/form-data" method="post" action="/">
    <input type="file" class="form-control" name="file">
    <button type = "submit" class = "btn btn-default">Submit</button>
</form>