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

Function uploadLargeFilesToProvider

apps/sim/providers/file-attachments.server.ts:108–133  ·  view source on GitHub ↗
(
  request: ProviderRequest,
  providerId: ProviderId | string
)

Source from the content-addressed store, hash-verified

106 * and BYOK keys both work.
107 */
108export async function uploadLargeFilesToProvider(
109 request: ProviderRequest,
110 providerId: ProviderId | string
111): Promise<void> {
112 if (getProviderFileStrategy(providerId) !== 'files-api') return
113
114 const groups = groupUploadableFiles(request.messages)
115 if (groups.length === 0) return
116
117 const maxBytes = getProviderAttachmentMaxBytes(providerId)
118 const ai = providerId === 'google' ? new GoogleGenAI({ apiKey: request.apiKey }) : null
119
120 for (const group of groups) {
121 const [representative] = group
122 await assertFileAccessForUpload(representative, request.userId)
123 if (providerId === 'openai') {
124 await uploadOpenAIFile(representative, request.apiKey, maxBytes, request.abortSignal)
125 } else if (ai) {
126 await uploadGeminiFile(representative, ai, maxBytes, request.abortSignal)
127 }
128 for (const file of group) {
129 file.providerFileId = representative.providerFileId
130 file.providerFileUri = representative.providerFileUri
131 }
132 }
133}
134
135/**
136 * Verifies the caller may read this file before its bytes are uploaded to a provider. Enforced

Callers 1

executeProviderRequestFunction · 0.90

Calls 6

getProviderFileStrategyFunction · 0.90
groupUploadableFilesFunction · 0.85
uploadOpenAIFileFunction · 0.85
uploadGeminiFileFunction · 0.85

Tested by

no test coverage detected