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