( opts: RunUploadStrategyOptions )
| 559 | * with code `FALLBACK_REQUIRED` is thrown so callers can fall back to a server-proxied path. |
| 560 | */ |
| 561 | export const runUploadStrategy = async ( |
| 562 | opts: RunUploadStrategyOptions |
| 563 | ): Promise<UploadStrategyResult> => { |
| 564 | const { |
| 565 | file, |
| 566 | presignedEndpoint, |
| 567 | presignedOverride, |
| 568 | presignedBody, |
| 569 | workspaceId, |
| 570 | context, |
| 571 | workflowId, |
| 572 | executionId, |
| 573 | signal, |
| 574 | onProgress, |
| 575 | } = opts |
| 576 | const contentType = getFileContentType(file) |
| 577 | |
| 578 | if (presignedOverride && !presignedOverride.directUploadSupported) { |
| 579 | throw new DirectUploadError('Server signaled fallback to API upload', 'FALLBACK_REQUIRED') |
| 580 | } |
| 581 | |
| 582 | if (file.size > LARGE_FILE_THRESHOLD) { |
| 583 | const { key, path } = await uploadViaMultipart({ |
| 584 | file, |
| 585 | workspaceId, |
| 586 | context, |
| 587 | workflowId, |
| 588 | executionId, |
| 589 | signal, |
| 590 | onProgress, |
| 591 | }) |
| 592 | return { key, path, name: file.name, size: file.size, contentType } |
| 593 | } |
| 594 | |
| 595 | let presigned: PresignedUploadInfo |
| 596 | if (presignedOverride) { |
| 597 | presigned = presignedOverride |
| 598 | } else { |
| 599 | if (!presignedEndpoint) { |
| 600 | throw new DirectUploadError( |
| 601 | 'runUploadStrategy requires either presignedEndpoint or presignedOverride', |
| 602 | 'PRESIGNED_URL_ERROR' |
| 603 | ) |
| 604 | } |
| 605 | presigned = await getPresignedUploadInfo({ |
| 606 | endpoint: presignedEndpoint, |
| 607 | file, |
| 608 | body: presignedBody, |
| 609 | signal, |
| 610 | }) |
| 611 | } |
| 612 | |
| 613 | if (!presigned.directUploadSupported) { |
| 614 | throw new DirectUploadError('Server signaled fallback to API upload', 'FALLBACK_REQUIRED') |
| 615 | } |
| 616 | |
| 617 | await uploadViaPresignedPut({ |
| 618 | file, |
no test coverage detected