[英]Sails js Error in file Upload
I have a form which have a input type file with name "uploadfile". 我有一个表单,其中的输入类型文件名为“ uploadfile”。 No error occurs while a file is selected and form is submitted.
选择文件并提交表单时没有错误发生。 But having this error while I don't select a file and submit the form.
但是,当我没有选择文件并提交表单时出现此错误。
` `
if(req.file('uploadfile')._files.length>0){
var ques_file = req.file('uploadfile');
console.log('here');
ques_file.upload({
saveAs: function(file, cb) {
cb(null, file.filename);
},
dirname: dirPath },function (err, files) {
if (err){
return res.serverError(err);
}else{
name =files[0].filename;
filename=name;
console.log("file : "+filename);
}
});
` And in commad having this error `并为此感到困惑
events.js:72
throw er; // Unhandled 'error' event
^
Error: ETIMEOUT: An Upstream (`NOOP_ques_uploadfile`) timed out waiting for file(s). No files were sent after waiting 10000ms.
at null.<anonymous> (C:\xampp\htdocs\kucbt_admin\node_modules\sails\node_modules\skipper\standalone\Upstream\Upstream.js:62:15)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
you should not use if statement for req.file()
, you can check the length of array inside the function whenDone
as in example below: 您不应该对
req.file()
使用if语句,可以在function whenDone
检查数组的长度,如下例所示:
req.file('avatar').upload({
saveAs: function(file, cb) {
cb(null, file.filename);
},
dirname: uploadPath
}, function whenDone(err, uploadedFiles) { //onUploadComplete
if (uploadedFiles.length==0) {
//if no file selected.
sails.log.info('nothing selected');
return res.view('showimage');
}
if (err){
return res.serverError(err);
} else{
return res.view('showimage', {file:uploadedFiles});
}
});
Try installing 0.5.5 of Skipper- the default ETIMEOUT timer was extended. 尝试安装0.5.5的Skipper-默认的ETIMEOUT计时器已扩展。 Also in past versions, ETIMEOUT issues for many users were coming from multiparty form upload errors (ie unknown content-type) that were getting eaten by the ETIMEOUT.
同样在过去的版本中,许多用户的ETIMEOUT问题是由ETIMEOUT吞噬的多方表单上载错误(即未知的内容类型)引起的。
To install skipper@0.5.5, you can directly bring it in as the bodyparser in your project by doing npm install skipper --save
in your project and configuring it as middleware , or you can just install Sails v0.11.x, which comes with the updated version. 要安装skipper@0.5.5,您可以通过在项目中执行
npm install skipper --save
并将其配置为中间件来直接将其作为bodyparser引入项目中,也可以仅安装Sails v0.11.x,即可带有更新的版本。
As of today, Sails v0.11 is released with the "beta" tag on npm, so you can install it directly in your project using: 从今天起,Sails v0.11随npm一起发布,带有“ beta”标签,因此您可以使用以下命令直接将其安装在项目中:
npm install sails@beta --save
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.