繁体   English   中英

文件上传期间发生ETIMEOUT。 帆船JS

[英]ETIMEOUT during file upload. SAILS JS

我有一个带有文件上传字段的表单。 如果我上传文件,它的工作正常。 但是,当我提交带有out文件的表单时,它会重定向到预期的页面,并且也会出现ETIMEOUT错误。

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ETIMEOUT: An Upstream (`NOOP_avatar`) timed out waiting
iles were sent after waiting 500ms.
    at null.<anonymous> (C:\xampp\htdocs\fileuploadtest\node_m
ndalone\Upstream\Upstream.js:58:15)

我的代码如下所示:

upload_image: function (req, res) {
    var uploadPath = '../../assets/images/uploads/';
    console.log(req.file('avatar')._files);
    if(req.file('avatar')._files.length > 0){
      req.file('avatar').upload({
          saveAs: function(file, cb) {
            cb(null, file.filename);
          },
          dirname: uploadPath
        }, function whenDone(err, uploadedFiles) {
          if (err){
            return res.serverError(err);
          } else{
            return res.view('showimage', {file:uploadedFiles});
          }
        });
    }else{
      console.log('no data');
       return res.view('showimage');
    }
  },

它重定向到showimage但也给出错误。

使用req.file('avatar')将尝试检查尚未上传的文件,因此使用if条件将给您一个错误。 使用.upload()函数后,尝试使用if条件。

req.file('avatar').upload({
  saveAs: function(file, cb) {
    cb(null, file.filename);
  },
  dirname: uploadPath
}, function whenDone(err, uploadedFiles) {
  if (err){
    return res.serverError(err);
  } 
  if(uploadedFiles.length!=0){
    return res.view('showimage', {file:uploadedFiles});
  }else{
   return res.view('showimage', {file:"No files uploaded."});
   }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM