Error EMAXBUFFER

I have a code that updates some information about the studio and, if necessary, uploads a new image.

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);
    });
  }
});}

If I edit all the fields (including the image), everything is fine. But if I didn’t select the image, everything will work as it should, the update will be successful and redirect the code, as it should. Then comes this error:

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)

If I comment on everything that belongs to uploading images, no error is displayed.

+3
source share
1 answer

In the documentation: https://sailsjs.com/documentation/reference/configuration/sails-config-http

Skipper, , 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

0

Source: https://habr.com/ru/post/1613787/


All Articles