首页 文章

使用 Connect Multiparty 在节点 js 中中止处理请求

提问于
浏览
6
Error: Request aborted
at IncomingMessage.onReqAborted (D:\ProjectName\node_modules\express\node_modules\connect\node_modules\multiparty\index.js:131:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1911:11)
at Socket.serverSocketCloseListener (http.js:1923:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:466:12)

使用 connect multiparty 中间件在节点 js 中上传多个文件时出现此错误。我甚至没有上传大尺寸文件。它不超过 50mb。在上传文件时断开互联网连接时特别是出现此错误。有没有办法处理这个错误。

2 回答

  • 0

    您应该使用 Multer js 进行文件上传。

  • 0

    在我的情况下,我可以解决添加更多请求/响应超时。

    如果您使用快递:

    var server = app.listen(app.get('port'), function() {
      debug('Express server listening on port ' + server.address().port);
    });
    server.timeout = 1000 * 60 * 10; // 10 min
    

    Connect/Express 还有一个中间件:https://github.com/expressjs/timeout

    如果您不使用快递,并且只使用 vanilla 节点:

    var http = require('http');
    var server = http.createServer(function (req, res) {
      setTimeout(function() {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end('Hello World\n');
      }, 200);
    }).listen(3000, '127.0.0.1');
    
    server.timeout = 1000 * 60 * 10; // 10 min
    console.log('Server running at http://127.0.0.1:3000/');
    

相关问题