Spaces:
Configuration error
Configuration error
File size: 613 Bytes
0d3c552 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | export const fileToBase64 = (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
const result = reader.result as string;
// The result is "data:application/pdf;base64,xxxxx..."
// We only need the part after the comma.
const base64String = result.split(',')[1];
if (base64String) {
resolve(base64String);
} else {
reject(new Error("Failed to read file as base64."));
}
};
reader.onerror = (error) => reject(error);
});
};
|