MCPcopy Index your code
hub / github.com/simstudioai/sim / runUploadStrategy

Function runUploadStrategy

apps/sim/lib/uploads/client/direct-upload.ts:561–632  ·  view source on GitHub ↗
(
  opts: RunUploadStrategyOptions
)

Source from the content-addressed store, hash-verified

559 * with code `FALLBACK_REQUIRED` is thrown so callers can fall back to a server-proxied path.
560 */
561export 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,

Callers 8

uploadOneFileFunction · 0.90
useProfilePictureUploadFunction · 0.90
useWorkspaceLogoUploadFunction · 0.90
useFileAttachmentsFunction · 0.90
startFunction · 0.90
uploadWorkspaceFileFunction · 0.90

Calls 4

getFileContentTypeFunction · 0.90
uploadViaMultipartFunction · 0.85
getPresignedUploadInfoFunction · 0.85
uploadViaPresignedPutFunction · 0.85

Tested by

no test coverage detected