Node.js服务器说,请求被取消,客户说套接字挂断

您好,我正在Loopback上的Node.js平台上的REST API上工作。 我在Linux Mint 17 Quianatesting。

与Multipart / form-data请求相关时,遇到问题。 testing是:

it('Multipart request with two files, one right', function(done) { var formData = { 'dailyThemesId':'1', 'themeId':'1', 'pictureTimeZone':'GTM+1', 'pictureText':'Pretty pics', file: { value: fs.createReadStream('./test/File/fileSuperSmall.mp4'), options: { filename: 'video.mp4', contentType: 'video/mp4' } }, video: { value: fs.createReadStream('./test/File/fileSuperSmall.mp4'), options: { filename: 'video.mp4', contentType: 'video/mp4' } } }; request2.post({url: 'http://0.0.0.0:3000' +'/api/Pictures/upload' +'?access_token='+token1, formData: formData}, function optionalCallback(err, httpResponse, body) { if (err) { return console.error('upload failed:', err); } console.log('Upload successful! Server responded with:', body); }); 

});

当这个testing运行时,我得到下一个日志。

上传失败:{[错误:套接字挂断]代码:'ECONNRESET'}

据我所知,它看起来像服务器在file upload时停止了连接。

在服务器端为file upload创build自定义端点。 预计该端点将收到多部分请求。 parsing是使用多方完成的。

  Pictures.upload = function(req, callback) { var form = new Multiparty.Form({}), currentTime = new Date(), clientId, dailyThemesId, themeId, pictureTimeZone, pictureText, file; if (req.accessToken) { clientId = req.accessToken.userId; } else { return callback(new Error('Error: To upload a file you must be logged')); } if (!req.get('Content-Type').includes('multipart/form-data')) { return callback(new Error('Error: Message must be a Multipart')); } form.on('part', function(part) { part.on('error', function(err) { console.log('Error at part parsing :', err, err.stack); // error handled at form level }); if (part.name === 'file' && part.filename.endsWith('.mp4')) { file = part; console.log('file found'); } }); form.on('field', function (name, value){ if (name === 'dailyThemesId') { dailyThemesId = value; } else if (name === 'themeId') { themeId = value; } else if (name === 'pictureTimeZone') { pictureTimeZone = value; } else if (name === 'pictureText') { pictureText = value; } }); form.on('error', function (err) { console.log('Error at form parsing :', err, err.stack); }); form.on('progress', function (bytesReceived, bytesExpected) { console.log('So far recieved bytes: ', bytesReceived); if (bytesReceived >= 1024000000) { console.log('Message is way too long'); return callback(new Error('Http request in way to long')); } }); form.on('close', function () { console.log('Closed multipart'); if (dailyThemesId && themeId && pictureTimeZone && pictureText && file && (process.env.NODE_SFTP_HOST === '127.0.0.0' || process.env.NODE_SFTP_HOST === 'localhost')) { console.log('Sending local'); sendFile (fs, file); } else if (dailyThemesId && themeId && pictureTimeZone && pictureText && file ) { console.log('Sending ftp'); startSftpConn(file); } else { console.log('Missing something'); return callback(new Error('Missing data at the request')); } }); form.parse(req); 

每次上传文件时,都会logging下一个错误。

错误:[InvalidMessage.onReqAborted(/home/francisco/NodeJs/dayN/node_modules/multiparty/index.js:183:17)IncomingMessage错误:请求中止在窗体分析:[错误:请求中止]错误:请求中止IncomingMessage.onReqAborted (events.js:179:7)的emitNone(events.js:80:13)上的/home/francisco/NodeJs/dayN/node_modules/continuation-local-storage/context.js:76:17)在Socket.serverSocketCloseListener(_http_server。)上的abortIncoming(_http_server.js:284:11)处的IncomingMessage.emitted [as emit](/home/francisco/NodeJs/dayN/node_modules/emitter-listener/listener.js:122:21)在TCP._onclose(net.js:484:12)处的Socket.emit(events.js:182:7)处的emitOne(events.js:95:20)处的js:297:5)

最后,我不确定为什么会发生这种情况,怎么两个人都报告说另一端完成了连接? 当没有涉及的文件,它完美的作品。 ¿可能是一个回环的事情,不允许长消息? 任何帮助表示赞赏,那么你。