Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle Array buffer allocation failed in nodejs?

I have successfully upload image in nodejs and I am using multer for that. But sometime " Array buffer allocation failed " error occurs and I want to handle that error. I tried to keep the code in try-catch block even though still it throws the error and I am unable to figure out how to handle this error or how to avoid that error ? Able to upload file but when I try to change height and width and making a new image then it throws an error

Uncaught RangeError: Array buffer allocation failed

 at Buffer.Uint8Array (native)

 at FastBuffer (buffer.js:8:1)

OR

 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)

Any suggestion will be much more helpful

like image 710
VIKAS KOHLI Avatar asked Aug 28 '17 13:08

VIKAS KOHLI


3 Answers

Looks like you do not have enough memory to perform a large size upload

like image 68
Amir Avatar answered Nov 06 '22 15:11

Amir


Someone in our team had this issue, so we guessed something was off with his machine. Turns out he had node x86 installed. After installing node x64 and rebuilding all the node_modules, the error was gone.

like image 4
JJP Avatar answered Nov 06 '22 15:11

JJP


jpeg-js uses inadequate amount of memory for image processing,

- possible solution could be to resize picture (imagemagick/whatever)

like image 2
IvanM Avatar answered Nov 06 '22 13:11

IvanM