Spaces:
Configuration error
Configuration error
Download utils/file.ts from rachel521/sci_helper: direct link, hf CLI and curl.
- Browser
- Download file 613 Bytes
-
https://huggingface.co/spaces/rachel521/sci_helper/resolve/main/utils/file.ts
- Command line
-
hf download hf://spaces/rachel521/sci_helper/utils/file.ts
-
curl -L -o file.ts https://huggingface.co/spaces/rachel521/sci_helper/resolve/main/utils/file.ts
613 Bytes
| 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); | |
| }); | |
| }; | |