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

Function downloadFileFromStorage

apps/sim/lib/uploads/utils/file-utils.server.ts:266–304  ·  view source on GitHub ↗
(
  userFile: UserFile,
  requestId: string,
  logger: Logger,
  options: { maxBytes?: number } = {}
)

Source from the content-addressed store, hash-verified

264 * @returns Buffer containing file data
265 */
266export async function downloadFileFromStorage(
267 userFile: UserFile,
268 requestId: string,
269 logger: Logger,
270 options: { maxBytes?: number } = {}
271): Promise<Buffer> {
272 let buffer: Buffer
273 if (options.maxBytes !== undefined && userFile.size > options.maxBytes) {
274 assertKnownSizeWithinLimit(userFile.size, options.maxBytes, 'storage file download')
275 }
276
277 if (isExecutionFile(userFile)) {
278 logger.info(`[${requestId}] Downloading from execution storage: ${userFile.key}`)
279 const { downloadExecutionFile } = await import(
280 '@/lib/uploads/contexts/execution/execution-file-manager'
281 )
282 buffer = await downloadExecutionFile(userFile, { maxBytes: options.maxBytes })
283 } else if (userFile.key) {
284 const context = (userFile.context as StorageContext) || inferContextFromKey(userFile.key)
285 logger.info(
286 `[${requestId}] Downloading from ${context} storage (${userFile.context ? 'explicit' : 'inferred'}): ${userFile.key}`
287 )
288
289 const { downloadFile } = await import('@/lib/uploads/core/storage-service')
290 buffer = await downloadFile({
291 key: userFile.key,
292 context,
293 maxBytes: options.maxBytes,
294 })
295 } else {
296 throw new Error('File has no key - cannot download')
297 }
298
299 if (options.maxBytes !== undefined) {
300 assertKnownSizeWithinLimit(buffer.length, options.maxBytes, 'storage file download')
301 }
302
303 return buffer
304}
305
306/**
307 * Result of {@link downloadServableFileFromStorage}: the bytes a consumer should

Callers 10

readUserFileContentFunction · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
generateWithRunwayFunction · 0.90

Calls 6

isExecutionFileFunction · 0.90
inferContextFromKeyFunction · 0.90
downloadExecutionFileFunction · 0.85
infoMethod · 0.80
downloadFileFunction · 0.50

Tested by

no test coverage detected