I have a form which have a input type file with name "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('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});
}
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加