如何处理nodejs中的数组缓冲区分配失败?

VIK*_*HLI 7 arrays buffer image node.js

我已经成功上传了nodejs中的图片,我正在使用multer.但有时"阵列缓冲区分配失败"错误发生,我想处理该错误.我试图将代码保留在try-catch块中,即使它仍然会抛出错误,我无法弄清楚如何处理此错误或如何避免该错误?能够上传文件,但当我尝试更改高度和宽度并制作新图像时,它会抛出错误

Uncaught RangeError: Array buffer allocation failed

 at Buffer.Uint8Array (native)

 at FastBuffer (buffer.js:8:1)
Run Code Online (Sandbox Code Playgroud)

要么

 Array buffer allocation failed

   at Buffer.Uint8Array (native)

   at FastBuffer (buffer.js:8:1)

   RangeError: Array buffer allocation failed
    at new Uint8Array (native)
    at Object.getData (/Burg_nodejs/node_modules/jpeg-js/lib/decoder.js:797:18)
    at Object.copyToImageData (/Burg_nodejs/node_modules/jpeg-js/lib/decoder.js:913:23)
    at Object.decode (/Burg_nodejs/node_modules/jpeg-js/lib/decoder.js:985:11)
    at Jimp.parseBitmap (/Burg_nodejs/node_modules/jimp/index.js:310:36)
    at /Burg_nodejs/node_modules/jimp/index.js:202:29
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:446:3)
Run Code Online (Sandbox Code Playgroud)

任何建议都会更有帮助

JJP*_*JJP 10

我们团队中有人遇到了这个问题,所以我们猜测他的机器出了问题。结果他安装了node x86。安装node x64并重建所有node_modules后,错误消失了。


小智 9

您似乎没有足够的内存来执行大尺寸上传