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

Function downloadFileStream

apps/sim/lib/uploads/core/storage-service.ts:409–430  ·  view source on GitHub ↗
(options: {
  key: string
  context: StorageContext
})

Source from the content-addressed store, hash-verified

407 * import worker so a multi-hundred-MB file is never held resident.
408 */
409export async function downloadFileStream(options: {
410 key: string
411 context: StorageContext
412}): Promise<Readable> {
413 const { key, context } = options
414 const config = getStorageConfig(context)
415
416 if (USE_BLOB_STORAGE) {
417 const { downloadFromBlobStream } = await import('@/lib/uploads/providers/blob/client')
418 return downloadFromBlobStream(key, createBlobConfig(config))
419 }
420
421 if (USE_S3_STORAGE) {
422 const { downloadFromS3Stream } = await import('@/lib/uploads/providers/s3/client')
423 return downloadFromS3Stream(key, createS3Config(config))
424 }
425
426 const { createReadStream } = await import('fs')
427 const { join } = await import('path')
428 const { UPLOAD_DIR_SERVER } = await import('./setup.server')
429 return createReadStream(join(UPLOAD_DIR_SERVER, sanitizeFileKey(key)))
430}
431
432/**
433 * Delete a file from the configured storage provider

Callers 2

getCsvPreviewSliceFunction · 0.90
runTableImportFunction · 0.90

Calls 6

getStorageConfigFunction · 0.90
sanitizeFileKeyFunction · 0.90
downloadFromBlobStreamFunction · 0.85
createBlobConfigFunction · 0.85
downloadFromS3StreamFunction · 0.85
createS3ConfigFunction · 0.85

Tested by

no test coverage detected