gpt4 book ai didi

javascript - 使用 node 和 express 上传一个大文件(1GB)

转载 作者:搜寻专家 更新时间:2023-11-01 00:02:39 24 4
gpt4 key购买 nike

尝试使用 express 将大文件上传到 Node js 实例,但大文件会失败。出现以下错误消息:

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...

当我不想分块数据时,我该怎么做才能避免这个错误?

希望有人能帮忙解决;-)

最佳答案

如果分析错误信息

buffer.js:194
this.parent = new SlowBuffer(this.length);
^
RangeError: length > kMaxLength

可以看到kMaxLength是一个常量,指定进程的内存限制。
来自 https://github.com/joyent/node/wiki/FAQ

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.

所以你可以用标志执行 Node

node --max-old-space-size=2000 app.js

标志单位以 MB 为单位,请参阅 ( https://github.com/joyent/node/blob/master/deps/v8/ChangeLog)

关于javascript - 使用 node 和 express 上传一个大文件(1GB),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17969880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com