{"record":{"id":"8d2513d9efe3f84b","repo":"danny-avila/LibreChat","slug":"file-size-is-fileinfo-size-bytes-it-exceeds-th","errorCode":null,"errorMessage":"File size is ${fileInfo.size} bytes. It exceeds the maximum limit of ${maxFileSize} bytes.","messagePattern":"File size is (.+?) bytes\\. It exceeds the maximum limit of (.+?) bytes\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"api/server/utils/import/importConversations.js","lineNumber":20,"sourceCode":"const { resolveImportMaxFileSize } = require('@librechat/api');\nconst { logger } = require('@librechat/data-schemas');\nconst { getImporter } = require('./importers');\nconst { createImportBatchBuilder } = require('./importBatchBuilder');\n\nconst maxFileSize = resolveImportMaxFileSize();\n\n/**\n * Job definition for importing a conversation.\n * @param {{ filepath: string, requestUserId: string, userRole?: string, interfaceConfig?: object }} job\n */\nconst importConversations = async (job) => {\n  const { filepath, requestUserId, userRole, interfaceConfig } = job;\n  try {\n    logger.debug(`user: ${requestUserId} | Importing conversation(s) from file...`);\n\n    const fileInfo = await fs.stat(filepath);\n    if (fileInfo.size > maxFileSize) {\n      throw new Error(\n        `File size is ${fileInfo.size} bytes. It exceeds the maximum limit of ${maxFileSize} bytes.`,\n      );\n    }\n\n    const fileData = await fs.readFile(filepath, 'utf8');\n    const jsonData = JSON.parse(fileData);\n    const importer = getImporter(jsonData);\n    await importer(\n      jsonData,\n      requestUserId,\n      (userId) => createImportBatchBuilder(userId, interfaceConfig),\n      userRole,\n    );\n    logger.debug(`user: ${requestUserId} | Finished importing conversations`);\n  } catch (error) {\n    logger.error(`user: ${requestUserId} | Failed to import conversation: `, error);\n    throw error; // throw error all the way up so request does not return success\n  } finally {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/utils/import/importConversations.js#L2-L38","documentation":"Thrown by importConversations when fs.stat(filepath).size exceeds maxFileSize (resolved once at module load via resolveImportMaxFileSize()). The guard prevents reading and JSON.parsing arbitrarily large uploads in the event loop. The limit is configurable through the resolver's env/source, so the threshold reflects deployment policy.","triggerScenarios":"Uploading a conversation export larger than the configured limit; the limit being left at its default while exports grow; importing a long-running account history that accumulated many messages.","commonSituations":"Default limit too low for power users; env var controlling the limit not set in production; combining many conversations into one file.","solutions":["Split the export into smaller files below the limit before importing.","Raise the configured max file size via the environment variable read by resolveImportMaxFileSize (set it and restart the worker).","If the limit cannot be raised, prune attachments/large message content from the export first."],"exampleFix":"// before: default limit too small for this export\n// after: raise the limit in the environment before starting the API\n//   (set the variable read by resolveImportMaxFileSize, e.g.)\nIMPORT_MAX_FILE_SIZE_BYTES=52428800  # 50 MiB\n\n// then at the call site, validate early:\nconst stat = await fs.stat(filepath);\nif (stat.size > maxFileSize) {\n  return res.status(413).json({ message: `Export too large: ${stat.size} bytes` });\n}","handlingStrategy":"validation","validationCode":"const stat = await fs.stat(filepath);\nif (stat.size > maxFileSize) {\n  throw new Error(`File size is ${stat.size} bytes. It exceeds the maximum limit of ${maxFileSize} bytes.`);\n}","typeGuard":"const isWithinImportLimit = (size, max) => typeof size === 'number' && size <= max;","tryCatchPattern":"try {\n  await importConversations(job);\n} catch (err) {\n  if (err.message.includes('exceeds the maximum limit')) {\n    return res.status(413).json({ message: err.message });\n  }\n  throw err;\n}","preventionTips":["Enforce a client-side size check before upload.","Set the max-file-size env var to match real export sizes.","Split large exports into multiple smaller files."],"tags":["import","validation","config","file-size"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}