MCPcopy
hub / github.com/simstudioai/sim / initiateS3MultipartUpload

Function initiateS3MultipartUpload

apps/sim/lib/uploads/providers/s3/client.ts:341–373  ·  view source on GitHub ↗
(
  options: S3MultipartUploadInit
)

Source from the content-addressed store, hash-verified

339 * Initiate a multipart upload for S3
340 */
341export 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

Callers 2

createS3BackendFunction · 0.85
route.tsFile · 0.85

Calls 5

sanitizeFileNameFunction · 0.90
generateIdFunction · 0.90
getS3ClientFunction · 0.85
sendMethod · 0.80

Tested by

no test coverage detected