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

1.9k views Asked by At

I have file upload system in node.js with multiparty package

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

                 })

        });

Its works fine but when upload larger files usually greater than 20 MB i got this error

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)

I know its solved with increase the timeout but i don't know how to in sails.js framerwork

1

There are 1 answers

2
sgress454 On BEST ANSWER

The request timeout is a feature of Node.js; there's nothing Sails-specific about it. From the 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.

So in your Sails.js action, do req.setTimeout(4 * 60 * 1000) if you want to increase the timeout to 4 minutes.

You might also look into using the built-in file upload capabilities of Sails!