Node.js 1gb csvfile upload – 错误:请求中止
我有一个大file upload的问题。 我试图上传较小的文件,它的工作很好,但是当我尝试上传较大的文件(700MB和更多)时,node.js服务器给我一个错误:
Error: Request aborted at IncomingMessage.onReqAborted (/home/xxx/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:465:12)
它甚至没有达到阅读状态。
我用
- 谷歌浏览器
- expression3.0
我已经包括在内
app.use(express.bodyParser({limit: '2048mb'}));
另外我想我应该提到这一点; 得到上述错误后,文件开始再次上传失败。 再次,小文件没有问题。 所以我的问题是我怎样才能有效地使用这种方法stream大文件,或者有更好的方法来做到这一点? 谢谢。
下面的代码是什么?
var formidable = require('formidable'), http = require('http'), util = require('util'); http.createServer(function(req, res) { if (req.url == '/upload' && req.method.toLowerCase() == 'post') { // parse a file upload var form = new formidable.IncomingForm(); form.parse(req, function(err, fields, files) { res.writeHead(200, {'content-type': 'text/plain'}); res.write('Received upload:\n\n'); res.end(util.inspect(files)); }); return; } // show a file upload form res.writeHead(200, {'content-type': 'text/html'}); res.end( '<form action="/upload" enctype="multipart/form-data" method="post">'+ '<input type="file" name="upload" multiple="multiple"><br>'+ '<input type="submit" value="Upload">'+ '</form>' ); }).listen(80);
来源: felixge / node-strongidable
在客户端,你需要提到enctype="multipart/form-data"