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

Function downloadFile

apps/sim/lib/uploads/core/storage-service.ts:366–402  ·  view source on GitHub ↗
(options: DownloadFileOptions)

Source from the content-addressed store, hash-verified

364 * Download a file from the configured storage provider
365 */
366export async function downloadFile(options: DownloadFileOptions): Promise<Buffer> {
367 const { key, context, maxBytes } = options
368
369 if (context) {
370 const config = getStorageConfig(context)
371
372 if (USE_BLOB_STORAGE) {
373 const { downloadFromBlob } = await import('@/lib/uploads/providers/blob/client')
374 const blobConfig = createBlobConfig(config)
375 return maxBytes === undefined
376 ? downloadFromBlob(key, blobConfig)
377 : downloadFromBlob(key, blobConfig, maxBytes)
378 }
379
380 if (USE_S3_STORAGE) {
381 const { downloadFromS3 } = await import('@/lib/uploads/providers/s3/client')
382 const s3Config = createS3Config(config)
383 return maxBytes === undefined
384 ? downloadFromS3(key, s3Config)
385 : downloadFromS3(key, s3Config, maxBytes)
386 }
387 }
388
389 const { readFile, stat } = await import('fs/promises')
390 const { join } = await import('path')
391 const { UPLOAD_DIR_SERVER } = await import('./setup.server')
392
393 const safeKey = sanitizeFileKey(key)
394 const filePath = join(UPLOAD_DIR_SERVER, safeKey)
395
396 if (maxBytes !== undefined) {
397 const fileStats = await stat(filePath)
398 assertKnownSizeWithinLimit(fileStats.size, maxBytes, 'storage download')
399 }
400
401 return readFile(filePath)
402}
403
404/**
405 * Stream a file out of the configured storage provider without buffering it in memory.

Callers 15

copyKbDocumentBlobFunction · 0.90
resolveInputFilesFunction · 0.90
loadCompiledDocFunction · 0.90
fetchWorkspaceFileBufferFunction · 0.90
downloadCopilotFileFunction · 0.90
serveInlineImageFunction · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
handleCloudProxyFunction · 0.90
handleCloudProxyPublicFunction · 0.90
route.tsFile · 0.90

Calls 8

getStorageConfigFunction · 0.90
sanitizeFileKeyFunction · 0.90
createBlobConfigFunction · 0.85
downloadFromBlobFunction · 0.85
createS3ConfigFunction · 0.85
downloadFromS3Function · 0.85
readFileFunction · 0.85

Tested by

no test coverage detected