| 404 | * Generate presigned URLs for uploading parts to S3 |
| 405 | */ |
| 406 | export async function getS3MultipartPartUrls( |
| 407 | key: string, |
| 408 | uploadId: string, |
| 409 | partNumbers: number[], |
| 410 | customConfig?: S3Config |
| 411 | ): Promise<S3PartUploadUrl[]> { |
| 412 | const config = customConfig || { bucket: S3_KB_CONFIG.bucket, region: S3_KB_CONFIG.region } |
| 413 | const s3Client = getS3Client() |
| 414 | |
| 415 | const presignedUrls = await Promise.all( |
| 416 | partNumbers.map(async (partNumber) => { |
| 417 | const command = new UploadPartCommand({ |
| 418 | Bucket: config.bucket, |
| 419 | Key: key, |
| 420 | PartNumber: partNumber, |
| 421 | UploadId: uploadId, |
| 422 | }) |
| 423 | |
| 424 | const url = await getSignedUrl(s3Client, command, { expiresIn: 3600 }) |
| 425 | return { partNumber, url } |
| 426 | }) |
| 427 | ) |
| 428 | |
| 429 | return presignedUrls |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Build a fallback object URL for when the SDK omits `Location` on multipart |