( key: string, uploadId: string, parts: S3MultipartPart[], customConfig?: S3Config )
| 460 | * Complete multipart upload for S3 |
| 461 | */ |
| 462 | export async function completeS3MultipartUpload( |
| 463 | key: string, |
| 464 | uploadId: string, |
| 465 | parts: S3MultipartPart[], |
| 466 | customConfig?: S3Config |
| 467 | ): Promise<{ location: string; path: string; key: string }> { |
| 468 | const config = customConfig || { bucket: S3_KB_CONFIG.bucket, region: S3_KB_CONFIG.region } |
| 469 | const s3Client = getS3Client() |
| 470 | |
| 471 | const command = new CompleteMultipartUploadCommand({ |
| 472 | Bucket: config.bucket, |
| 473 | Key: key, |
| 474 | UploadId: uploadId, |
| 475 | MultipartUpload: { |
| 476 | Parts: parts.sort((a, b) => a.PartNumber - b.PartNumber), |
| 477 | }, |
| 478 | }) |
| 479 | |
| 480 | const response = await s3Client.send(command) |
| 481 | const location = response.Location || buildObjectFallbackUrl(config.bucket, config.region, key) |
| 482 | const path = `/api/files/serve/${encodeURIComponent(key)}` |
| 483 | |
| 484 | return { |
| 485 | location, |
| 486 | path, |
| 487 | key, |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Abort multipart upload for S3 |
no test coverage detected