{"record":{"id":"a9dedf61cde19736","repo":"danny-avila/LibreChat","slug":"empty-file-uploaded","errorCode":null,"errorMessage":"Empty file uploaded","messagePattern":"Empty file uploaded","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/server/services/Files/process.js","lineNumber":1328,"sourceCode":" * @param {number} [params.req.width]\n * @param {number} [params.req.height]\n * @param {number} [params.req.version]\n * @param {boolean} [params.image] - Whether the file expected is an image.\n * @param {boolean} [params.isAvatar] - Whether the file expected is a user or entity avatar.\n * @returns {void}\n *\n * @throws {Error} If a file exception is caught (invalid file size or type, lack of metadata).\n */\nfunction filterFile({ req, image, isAvatar }) {\n  const { file } = req;\n  const { endpoint, endpointType, file_id, width, height } = req.body;\n\n  if (!file_id && !isAvatar) {\n    throw new Error('No file_id provided');\n  }\n\n  if (file.size === 0) {\n    throw new Error('Empty file uploaded');\n  }\n\n  /* parse to validate api call, throws error on fail */\n  if (!isAvatar) {\n    isUUID.parse(file_id);\n  }\n\n  if (!endpoint && !isAvatar) {\n    throw new Error('No endpoint provided');\n  }\n\n  const appConfig = req.config;\n  const fileConfig = mergeFileConfig(appConfig.fileConfig);\n\n  const endpointFileConfig = getEndpointFileConfig({\n    endpoint,\n    fileConfig,\n    endpointType,","sourceCodeStart":1310,"sourceCodeEnd":1346,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/process.js#L1310-L1346","documentation":"filterFile() throws this at process.js:1328 when multer populated req.file but file.size === 0. The guard exists because a zero-byte file would otherwise be saved, referenced by a file_id, and silently corrupt later processing (image resize, RAG ingest). It is an early, explicit failure for a degenerate multipart upload.","triggerScenarios":"A multipart upload whose file part has no content: the user picked a file then emptied it, a stream pipe closed before bytes flowed, or the client appended an empty Blob/File. Also seen when a proxy truncates the body.","commonSituations":"Drag-and-drop UI that lets a 0-byte file through. A frontend test that constructs FormData from an uninitialized Blob. Network middleware that strips the body under a size threshold.","solutions":["On the client, reject files with size === 0 before constructing the FormData.","Inspect the raw multipart payload (Network tab) to confirm the file part carries bytes.","If using a streaming source, ensure the stream has ended and emitted data before appending."],"exampleFix":"// before\nform.append('file', new Blob([]), 'empty.txt');\n// after\nif (selectedFile.size === 0) { alert('File is empty'); return; }\nform.append('file', selectedFile, selectedFile.name);","handlingStrategy":"validation","validationCode":"function isValidUploadFile(file) {\n  return !!file && typeof file.size === 'number' && file.size > 0;\n}","typeGuard":"const isNonEmptyFile = (f) => !!f && f.size > 0;","tryCatchPattern":null,"preventionTips":["Reject size === 0 in the file picker before constructing FormData.","Log selectedFile.size in dev builds to catch empty selections early."],"tags":["files","validation","upload","multipart"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}