Appearance
Function: convertFileToBase64InChunks()
ts
function convertFileToBase64InChunks(file: File): Promise<string>;Defined in: src/utils/convertFileToBase64InChunks.ts:45
Convert a File to a base64 string by reading it in chunks.
Parameters
| Parameter | Type | Description |
|---|---|---|
file | File | The File object to convert. |
Returns
Promise<string>
A promise that resolves to the base64-encoded string.
Example
ts
const input = document.querySelector('input[type="file"]');
const base64 = await convertFileToBase64InChunks(input.files[0]);
console.log(base64.slice(0, 20)); // "iVBORw0KGgoAAAANSU..."