After retrieving a file list, I aim to transform it into a JSON array similar to:
[
{"name":"IDCard001.jpg","base64":"data:image/jpeg;base64,/9j/4AA.."},
{"name":"IDCard002.jpg","base64":"data:image/jpeg;base64,/9j/4AA.."},
]
This is the code I have written for this purpose:
const getBase64 = (file: File) => {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.onerror = (error) => reject(error);
reader.readAsDataURL(file);
});
};
const handleFiles = (files: Array<File>) => {
const list = files.map(async (file) => {
return {
name: file.name,
base64: await getBase64(file),
};
});
}
I am facing an issue where I cannot use 'list' as a simple array. How should I proceed?