How do i store all result data into pImages array i am getting the result but in that case i think async function will work but i dont know how to apply it. please help, my code is
exports.addImage = (req, res, next) => {
let imageArray = req.files.productImageArray;
if (!req.files || Object.keys(req.files).length === 0) {
return res.status(400).send("No files were uploaded.");
}
// here all images will be stored in array format
let pImages = [];
for (let f in imageArray) {
imagekit.upload(
{
file: imageArray[f].data, //required
fileName: imageArray[f].name, //required
customMetadata: {
color: req.body.productLabels[f],
default: req.body.defaultProduct[f]
}
},
function(error, result) {
if (error) console.log(error);
else {
console.log(result)
pImages.push(result)
}
}
);
}
console.log("p", pImages); //output p []
};
Thanks in Advance