req.files.thumbnail.path 报错,各位大大知道什么回事吗?
发布于 10 年前 作者 komla 5250 次浏览 最后一次编辑是 8 年前

app.get(’/test’,function(req,res){ res.render(‘admin/editArticle.ejs’,{ content:"" }) }) app.post(’/test’,function(req,res){ var tmpPath=req.files.thumbnail.path; console.log(tmpPath); })

ejs 代码 如下

<input type=“file” name=“thumbnail” id=“thumbnail”/>

报错如下~~ 我是在win 环境下的 express 3

500 TypeError: Cannot read property ‘thumbnail’ of undefined

3 回复

http://expressjs.jser.us/api.html#req.files
看下这里,你是不是哪里没有配置

有配置 app.use(express.bodyParser({ keepExtensions: true, uploadDir: ‘./public/upload’ }));

@komla './public/upload’文件夹需要手动创建的

回到顶部