Spaces:
Configuration error
Configuration error
| 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); | |
| }); | |
| }; | |