Spaces:
Running
Running
Download src/lib/utils/file2base64.ts from huggingchat/chat-ui: direct link, hf CLI and curl.
- Browser
- Download file 389 Bytes
-
https://huggingface.co/spaces/huggingchat/chat-ui/resolve/refs%2Fpr%2F511/src/lib/utils/file2base64.ts
- Command line
-
hf download hf://spaces/huggingchat/chat-ui@refs/pr/511/src/lib/utils/file2base64.ts
-
curl -L -o file2base64.ts https://huggingface.co/spaces/huggingchat/chat-ui/resolve/refs%2Fpr%2F511/src/lib/utils/file2base64.ts
389 Bytes
| const file2base64 = (file: File): Promise<string> => { | |
| return new Promise<string>((resolve, reject) => { | |
| const reader = new FileReader(); | |
| reader.readAsDataURL(file); | |
| reader.onload = () => { | |
| const dataUrl = reader.result as string; | |
| const base64 = dataUrl.split(",")[1]; | |
| resolve(base64); | |
| }; | |
| reader.onerror = (error) => reject(error); | |
| }); | |
| }; | |
| export default file2base64; | |