(url, buffer, file_name, onload = () => {})
| 47 | } |
| 48 | |
| 49 | export async function send(url, buffer, file_name, onload = () => {}) { |
| 50 | const file = new File( |
| 51 | [buffer], |
| 52 | file_name, |
| 53 | { type: 'application/octet-stream' } |
| 54 | ); |
| 55 | const form = new FormData(); |
| 56 | form.append('upload', file); |
| 57 | |
| 58 | log('send'); |
| 59 | const response = await fetch(url, { method: 'POST', body: form }); |
| 60 | |
| 61 | if (!response.ok) { |
| 62 | throw Error(`Network response was not OK, status: ${response.status}`); |
| 63 | } |
| 64 | onload(); |
| 65 | } |
| 66 | |
| 67 | export function sleep(ms = 0) { |
| 68 | return new Promise(resolve => setTimeout(resolve, ms)); |
no test coverage detected