node.js:请求在 sails.js 框架中的 IncomingMessage.onReqAborted 多方处中止

node.js:Request aborted at IncomingMessage.onReqAborted multiparty in sails.js framework

我在 node.js 中有文件上传系统,带有多方包

        var gm          = require('gm').subClass({imageMagick: true});
        var multiparty  = require('multiparty');

        var form        =  new multiparty.Form();

        var s3          =  sails.config.aws.main();

        var options     = {
            partSize: 5242880, queueSize: 1
        }
        form.parse(req, function(err, fields, files) {

            gm(files.fileToUpload[0].path)
                .resize(200,200,'^')
                .stream(function (err,buffer) {

                    s3.upload({
                        Bucket:'mybucket',
                        Body:buffer,
                        Key:'artwork-croppedimages/test.jpg'
                    },options,function(err, data) {
                        console.log("upload error",err);
                        console.log("data",data);
                    });

                 })

        });

它工作正常但是当上传通常大于 20 MB 的大文件时我收到了这个错误

Error: Request aborted
    at IncomingMessage.onReqAborted (/var/www/node/cushbuart/node_modules/multiparty/index.js:183:17)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:188:7)
    at abortIncoming (_http_server.js:381:9)
    at socketOnClose (_http_server.js:375:3)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:191:7)
    at TCP._handle.close [as _onclose] (net.js:511:12)

我知道它可以通过增加超时来解决,但我不知道如何在 sails.js framerwork

请求超时是Node.js的一个特性;没有什么是 Sails 特有的。来自 Node.js documentation:

request.setTimeout(timeout[, callback])

Added in: v0.5.9

  • timeout <number> Milliseconds before a request is considered to be timed out.
  • callback <Function> Optional function to be called when a timeout occurs. Same as binding to the timeout event.

Once a socket is assigned to this request and is connected socket.setTimeout() will be called.

所以在您的 Sails.js 操作中,如果您想将超时增加到 4 分钟,请执行 req.setTimeout(4 * 60 * 1000)

您也可以考虑使用 Sails 的 built-in file upload capabilities