( options: S3MultipartUploadInit )
| 339 | * Initiate a multipart upload for S3 |
| 340 | */ |
| 341 | export async function initiateS3MultipartUpload( |
| 342 | options: S3MultipartUploadInit |
| 343 | ): Promise<{ uploadId: string; key: string }> { |
| 344 | const { fileName, contentType, customConfig, customKey, purpose } = options |
| 345 | |
| 346 | const config = customConfig || { bucket: S3_KB_CONFIG.bucket, region: S3_KB_CONFIG.region } |
| 347 | const s3Client = getS3Client() |
| 348 | |
| 349 | const safeFileName = sanitizeFileName(fileName) |
| 350 | const uniqueKey = customKey || `kb/${generateId()}-${safeFileName}` |
| 351 | |
| 352 | const command = new CreateMultipartUploadCommand({ |
| 353 | Bucket: config.bucket, |
| 354 | Key: uniqueKey, |
| 355 | ContentType: contentType, |
| 356 | Metadata: { |
| 357 | originalName: sanitizeFilenameForMetadata(fileName), |
| 358 | uploadedAt: new Date().toISOString(), |
| 359 | purpose: purpose || 'knowledge-base', |
| 360 | }, |
| 361 | }) |
| 362 | |
| 363 | const response = await s3Client.send(command) |
| 364 | |
| 365 | if (!response.UploadId) { |
| 366 | throw new Error('Failed to initiate S3 multipart upload') |
| 367 | } |
| 368 | |
| 369 | return { |
| 370 | uploadId: response.UploadId, |
| 371 | key: uniqueKey, |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Upload a single multipart part from the server (Body in hand), returning its |
no test coverage detected