| 1 | export interface UploadResult { |
| 2 | id: string |
| 3 | } |
| 4 | |
| 5 | export class UploadError |
| 6 | status: number |
| 7 | constructor(message: |
| 8 | super(message) |
| 9 | this.status = |
| 10 | this.name = |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | export async function uploadFile |
| 15 | file: File |
| 16 | projectId: string |
| 17 | ): Promise<UploadResult |
| 18 | const formData = |
| 19 | formData.append('file |
| 20 | formData.append('projectId |
| 21 | |
| 22 | const res = |
| 23 | method: 'POST', |
| 24 | body: formData, |
| 25 | }) |
| 26 | |
| 27 | if (!res.ok |
| 28 | const data = |
| 29 | throw new UploadError( |
| 30 | } |
| 31 | |
| 32 | return (await res |
| 33 | } |
| 34 | |
| 35 | export async function uploadDataUrl |
| 36 | dataUrl: string, |
| 37 | projectId: string, |
| 38 | filename: string, |
| 39 | contentType = 'image/png' |
| 40 | ): Promise<UploadResult |
| 41 | const blob = |
| 42 | const file = |
| 43 | return uploadFile(file |
| 44 | } |