问题描述
尝试使用express将大文件上传到节点js实例,大文件将失败.带有以下错误消息:
Trying to upload a large file to a node js instance using express and it will fail with large files.With the following errormessage:
Error: Request aborted
at IncomingMessage.<anonymous> (/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js:107:19)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1892:11)
at Socket.serverSocketCloseListener (http.js:1904:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:466:12)
/server/upload/
buffer.js:194
this.parent = new SlowBuffer(this.length);
^
RangeError: length > kMaxLength
at new Buffer (buffer.js:194:21)
at fs.js:220:16
at Object.oncomplete (fs.js:107:15)
31 Jul 14:01:04 - [nodemon] app crashed - waiting for file changes before starting...
当我不想对数据进行分块处理时,该怎么办才能防止此错误?
What can I do to prevent this error when I don't want to chunk the data?
希望有人可以帮助解决;-)
Hope someone can help to solve ;-)
推荐答案
如果您分析错误消息
buffer.js:194
this.parent = new SlowBuffer(this.length);
^
RangeError: length > kMaxLength
您可以看到kMaxLength是一个常数,用于指定进程的内存限制.
来自 https://github.com/joyent/node/wiki/FAQ
You can see that kMaxLength is a constant that specify the memory limit of a process.
From https://github.com/joyent/node/wiki/FAQ
因此您可以执行带有标志的节点
So you can execute node with the flag
node --max-old-space-size=2000 app.js
标志单位以MB为单位,请参阅( https://github.com. com/joyent/node/blob/master/deps/v8/ChangeLog )
The flag units is in MB see ( https://github.com/joyent/node/blob/master/deps/v8/ChangeLog)
这篇关于上载带有节点的大文件(1GB)并表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!