node.js - EMAXBUFFER错误

标签 node.js sails.js

我有这样的代码,可以更新一些工作室信息,并在需要时下载新图像。

postupdate: function(req,res){
sails.log.info("Reporting from [studio/postupdate]");
var id = req.param('id');
var uploadFile = req.file('image');

Studio.findOne({id: id}).exec(function(err, studio){
  if(err) return res.negotiate(err);
  studio.name= req.param('name');
  studio.description = req.param('description');

  sails.log.debug(uploadFile._files.length);
  if(uploadFile._files.length){
    sails.log.debug("Trying to download image");

    var oldName = uploadFile._files[0].stream.filename;
    var newName;

    uploadFile.upload(
      {
        dirname: publicImgDir,
        saveAs: oldName
      },
      function (err, files) {
        if (err) return res.negotiate(err);
        var fd = fs.createReadStream(publicImgDir+oldName);
        var hash = crypto.createHash('sha256');
        hash.setEncoding('hex');

        fd.on('end', function () {
          hash.end();
          newName= hash.read()+Path.extname(oldName);

          sails.log.debug("Trying to rename downloaded file");
            fs.rename(publicImgDir+oldName, publicImgDir + newName, function (err) {
              if (err) {
                sails.log.debug("Trying to rename downloaded file[2]");
                fs.unlink(publicImgDir+oldName);
                fs.rename(publicImgDir+oldName,publicImgDir + newName);
              }
              sails.log.debug("Renaming complete");
              sails.log.debug("Trying to copy file to origin assets directory");

              Utilities.copyFile(publicImgDir+newName,
                originImgDir+ newName,
                function(err){if(err) sails.log.debug(err);});

              studio.image = newName;
              studio.save(function(err){
                return res.redirect('admin/studio/update/'+id);
              });
            });
        });
        fd.pipe(hash);
      });
  }else{
    studio.save(function(err){
      if (err) {
        return res.send(500);
      }
      return res.redirect('/admin/studio/update/'+id);
    });
  }
});}

如果我编辑所有字段(包括图像),一切正常。但是,如果我不选择图像 - 一切都按应有的方式运行,更新会成功执行并按应有的方式重定向代码。然后出现这个错误:

events.js:141
  throw er; // Unhandled 'error' event
  ^Error: EMAXBUFFER: An Upstream (`NOOP_image`) timed out before it was plugged into a receiver. It was still unused after waiting 4500ms. You can configure this timeout by changing the `maxTimeToBuffer` option.
at null.<anonymous> (........\npm\node_modules\sails\node_modules\skipper\standalone\Upstream\Upstream.js:86:15)
at Timer.listOnTimeout (timers.js:89:15)

如果我评论属于图像下载的所有内容 - 没有错误显示。

最佳答案

在文档中:https://sailsjs.com/documentation/reference/configuration/sails-config-http

要自定义 Skipper,首先确保在您的应用中执行 npm install skipper --save。接下来,取消注释 config/http.js 文件中的以下代码:

bodyParser: (function _configureBodyParser(){
  var skipper = require('skipper');
  var middlewareFn = skipper({
    strict: true,
    maxTimeToBuffer: 100000
});
  return middlewareFn;
})(),

enter image description here

关于node.js - EMAXBUFFER错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32957779/

相关文章:

javascript - sailsjs cors 错误请求仍然通过 Controller

node.js - 自动重新加载 sails.js/node.js 中的客户端文件

node.js - Node : how to communicate between two processes on two servers

android - 从 android 客户端发送套接字请求到 sails.js 0.11

node.js - 让 Sails 使用正确的 CoffeeScript 版本

javascript - 无法在 Sails JS 中创建版本化 API

javascript - 为什么在nodejs中打印对象名称是prototype.constructor的名称而不是构造函数的名称?

javascript - 将文本中的单词保存到数组中

node.js - 如何使用node正确创建HTTPS透明代理服务器?

node.js - 在 sails.js 中过滤用户帖子数据