上载带有节点的大文件(1GB)并表达 [英] Upload a large file (1GB) with node and express

查看:65
本文介绍了上载带有节点的大文件(1GB)并表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用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

当前,默认情况下,v8的32位内存限制为512mb 系统,在64位系统上为1gb.可以通过设置来提高限制 --max-old-space-size最大值为〜1gb(32位)和〜1.7gb(64位),但是建议您拆分单个进程 如果您遇到内存不足的问题,请分成几个工作人员.

Currently, by default v8 has a memory limit of 512mb on 32-bit systems, and 1gb on 64-bit systems. The limit can be raised by setting --max-old-space-size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits.

因此您可以执行带有标志的节点

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)并表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆