How would I merge those chunks in order to generate a base64 image that I can consider including those chunks that has the same files_id.
The problem with my current implementation below , the code below , is that there are pairs of chunks that must be joined (chunks with the same files_id) in order to generate a complete base64 but my current code below was not able to consider it that is why some of the base64 are not complete.
How are we going to generate finalFile for each pairs of chunks including those without pairs ?
Current Code implementation
let fileData = [];
console.log("Chunks:", chunks)
for (let i = 0; i < chunks.length; i++) {
fileData.push(chunks[i].data.toString('base64'));
}
//Display the chunks using the data URI format
let finalFile = 'data:' + docs[0].contentType + ';base64,' + fileData.join('');
Chunks data
chunks[
[
{
_id:5dba69411fe3d41714eafb64,
files_id:5dba69411fe3d41714eafb63,
n:0,
files_id:5dba69411fe3d41714eafb63,
n:0,
data:[
Binary
]
}
],
[
{
_id:5dba73dcc62fd339acd11759,
files_id:5dba73dcc62fd339acd11758,
n:0,
data:[
Binary
]
},
{
_id:5dba73dec62fd339acd11770,
files_id:5dba73dcc62fd339acd11758,
n:1,
data:[
Binary
]
}
],
[
{
_id:5dba73ddc62fd339acd11765,
files_id:5dba73ddc62fd339acd11764,
n:0,
data:[
Binary
]
}
]
]