| 97 | * Write a binary file (e.g. image) from base64 data. |
| 98 | */ |
| 99 | export async function putBinaryFile( |
| 100 | filePath: string, |
| 101 | base64: string, |
| 102 | mimeType: string, |
| 103 | ): Promise<void> { |
| 104 | const binary = atob(base64); |
| 105 | const bytes = new Uint8Array(binary.length); |
| 106 | for (let i = 0; i < binary.length; i++) { |
| 107 | bytes[i] = binary.charCodeAt(i); |
| 108 | } |
| 109 | await fetch(apiUrl(filePath), { |
| 110 | method: 'POST', |
| 111 | headers: { 'Content-Type': mimeType }, |
| 112 | body: bytes, |
| 113 | }); |
| 114 | } |
| 115 | |
| 116 | export async function deleteFilesByPaths(data: { file_paths: string[] }): Promise<void> { |
| 117 | const promises = data.file_paths.map(async (filePath) => { |