I’m working on an application that allows users to download images related to a project. Each project has several different images relating to them. On my application I have a button that allows users to specify an ID for a project and then download all the images for that project. I’m using JSZip to zip all the images and then download it to the users browser.
This implementation is working so far, but when the user tries to download images for a project that contains a lot images, once zip.generateAsync is called, the application crashes and returns the error:
RangeError: Array buffer allocation failed
I’m assuming this is because the size of the zip to be generated is too large which causes the crash. What can I do to navigate around this error as the user still needs to be able to access all the images?
//Iterate through all files found
for (let i = 0; i < filesArr.length; i += 2) {
zip.file(filesArr[i], filesArr[i + 1], { base64: true });
await timers.setTimeout(100);
}
console.log('files zipped')
let z = await zip.generateAsync({ type: "nodebuffer" })
//code is not making it past zip.generateAsync() when there are too many results
console.log('zip generated')
filesArr = [];
return res.send(z)