(uploadUrl: string, fileBuffer: Buffer)
| 70 | * @throws Error if the upload fails |
| 71 | */ |
| 72 | export async function uploadFile(uploadUrl: string, fileBuffer: Buffer): Promise<void> { |
| 73 | debug(`Uploading file (${fileBuffer.length} bytes)`) |
| 74 | |
| 75 | const response = await fetch(uploadUrl, { |
| 76 | method: 'PUT', |
| 77 | headers: { |
| 78 | 'Content-Type': 'application/octet-stream', |
| 79 | 'Content-Length': fileBuffer.length.toString(), |
| 80 | }, |
| 81 | body: fileBuffer, |
| 82 | }) |
| 83 | |
| 84 | if (!response.ok) { |
| 85 | const responseText = await response.text() |
| 86 | debug(`Upload failed - Status: ${response.status}, Response: ${responseText}`) |
| 87 | throw new ImportError(responseText || 'Upload failed', response.status) |
| 88 | } |
| 89 | |
| 90 | debug('File uploaded successfully') |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Builds the launch URL for opening in Deepnote. |
no test coverage detected