Javascript 使用未定义的busboy meanstack上载图像
我正在尝试制作一个带有图像上传功能的注册表单,因此我使用post和enctype=“multipart/form data”在ejs端获取值 每次尝试时都会显示此错误Javascript 使用未定义的busboy meanstack上载图像,javascript,node.js,express,mean-stack,busboy,Javascript,Node.js,Express,Mean Stack,Busboy,我正在尝试制作一个带有图像上传功能的注册表单,因此我使用post和enctype=“multipart/form data”在ejs端获取值 每次尝试时都会显示此错误 TypeError:无法读取行上未定义的属性“on” req.busboy.on('file', function(fieldname,file, filename,encoding,mimeType) 您能告诉我这个问题是关于什么的吗?在我看来,由于busboy不是中间件,它正在扩展请求,请参阅代码片段: var busboy
TypeError:无法读取行上未定义的属性“on”
req.busboy.on('file', function(fieldname,file, filename,encoding,mimeType)
您能告诉我这个问题是关于什么的吗?在我看来,由于busboy不是中间件,它正在扩展请求,请参阅代码片段:
var busboy = new Busboy({ headers: req.headers });
busboy.on('file',...
我以前使用过busboy上传图像,我将与您分享配置及其实现方式
var busboy = new Busboy({
headers: req.headers,
limits: {
fileSize: 6*1024*1024 //2MB limit
}
});
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {
//extract intput-field from upload-form
});
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
//process each file upload, check for size, mimetype,
//store if all checks passed, delete otherwise, move to
//next file
});
//finish call back when all files are uploaded
busboy.on('finish', function() {
//do cleanup and other related work
});
return req.pipe(busboy);
这里是公共要点的链接我改用multer,它工作正常
on('字段',…)的作用是什么?这是一个回调函数,它将提取上传表单的输入字段,基本上是任何不是文件类型的字段(如firstName、lastName等)。我根据您的修改了我的模块。错误消失了,但它现在甚至没有收到字段(firstName等)。你认为我从html方面正确地处理了它吗?我编辑了我的问题代码,如果您想查看一下,您可以放置一些控制台日志以查看是否调用了on字段吗?如果调用了yes,那么调用它的字段名的值是多少。只要表单中的输入字段在文件字段之前,它就应该可以访问。现在它不再显示错误,但不会收到字段,我无法将它们保存在mongoose上
var busboy = new Busboy({
headers: req.headers,
limits: {
fileSize: 6*1024*1024 //2MB limit
}
});
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {
//extract intput-field from upload-form
});
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
//process each file upload, check for size, mimetype,
//store if all checks passed, delete otherwise, move to
//next file
});
//finish call back when all files are uploaded
busboy.on('finish', function() {
//do cleanup and other related work
});
return req.pipe(busboy);