gpt4 book ai didi

javascript - 无法读取未定义的属性 'fileSize' (req.file) (multer)

转载 作者:行者123 更新时间:2023-12-03 04:36:09 26 4
gpt4 key购买 nike

代码:

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>
<小时/>

问题:

我做错了什么?

最佳答案

将 name = 'file' 添加到输入

<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>

关于javascript - 无法读取未定义的属性 'fileSize' (req.file) (multer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43295936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com