我尝试在 connect-multiparty
的帮助下将图像文件上传到服务器
router.post('/image', multipartMiddleware , function(req, res) {
console.log(req.body, req.file);
});
<form method="post" action="/products/image">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
但是上面控制台的结果是{ file: '156.jpg' } undefined
,即我可以获取文件名,但是为什么文件对象没有来?
最佳答案
文件内容位于代码中的 req.files
中,而不是 req.file
中。
并且还可以找到文件路径和文件名
var tmppath = req.files.file.path;
var tmpname = req.files.file.name;
这是一个link ,我用它来使用 Node.js
上传文件。
关于javascript - 连接多方中间获取文件请求未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34695032/