我正在使用强大的模块https://github.com/felixge/node-formidable来上传图像。我创建了一个单独的新项目,文件上传工作完美。
但是当我将它集成到我现有的项目中时。我收到以下错误:-
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)
知道如何解决这个问题吗?
我尝试了 ON 事件:-
form.on('progress', function (bytesReceived, bytesExpected) {
console.log('PROGRESS');
console.log(bytesReceived);
console.log(bytesExpected);
});
它给我上面代码的结果为:-
PROGRESS
0
488
它不会提前。
尝试在你的app.js中删除它:
app.use(express.bodyParser());
对于OP来说可能有点晚了,但对于其他人来说:只需设置/增加nodejs超时,如下所示:
server.timeout = 1000 * 60 * 10; // 10 mins
formidable 使用此设置后会抛出“abort”和“error”事件。你可以查看这个答案了解详情
对于较新版本的express(即
express@^4.x
),其中body-parser
已弃用,请删除、删除或注释掉条目app.use(express.json())
或.js
文件中的任何.ts
。