{"record":{"id":"080ecfe92b029062","repo":"danny-avila/LibreChat","slug":"remote-file-response-too-large-buffer-length-b","errorCode":null,"errorMessage":"Remote file response too large: ${buffer.length} bytes","messagePattern":"Remote file response too large: (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/server/services/Files/Azure/crud.js","lineNumber":84,"sourceCode":"  userId,\n  URL,\n  fileName,\n  basePath = defaultBasePath,\n  containerName,\n}) {\n  try {\n    const maxBytes = getRemoteFileFetchMaxBytes();\n    const response = await fetch(assertRemoteFileURL(URL), {\n      timeout: getRemoteFileFetchTimeoutMs(),\n      size: maxBytes,\n    });\n    if (!response.ok) {\n      throw new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`);\n    }\n    assertRemoteFileContentLength(response.headers, maxBytes);\n    const buffer = await response.buffer();\n    if (buffer.length > maxBytes) {\n      throw new Error(`Remote file response too large: ${buffer.length} bytes`);\n    }\n\n    return await saveBufferToAzure({ userId, buffer, fileName, basePath, containerName });\n  } catch (error) {\n    logger.error('[saveURLToAzure] Error uploading file from URL:', error);\n    throw error;\n  }\n}\n\n/**\n * Retrieves a blob URL from Azure Blob Storage.\n *\n * @param {Object} params\n * @param {string} params.fileName - The file name.\n * @param {string} [params.basePath='images'] - The base folder used during upload.\n * @param {string} [params.userId] - If files are stored in a user-specific directory.\n * @param {string} [params.containerName] - The Azure Blob container name.\n * @returns {Promise<string>} The blob's URL.","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/Azure/crud.js#L66-L102","documentation":"Thrown by saveURLToAzure (Azure/crud.js) when the fully buffered remote file exceeds getRemoteFileFetchMaxBytes(). node-fetch's `size` option is meant to abort mid-stream, but this is a defensive secondary check after response.buffer() resolves, catching cases where the Content-Length header was absent or lied.","triggerScenarios":"A remote file with no (or understated) Content-Length header streams more bytes than the configured cap once fully buffered; the size abort did not fire because the header was missing.","commonSituations":"REMOTE_FILE_FETCH_MAX_BYTES env var set too low for legitimate use; user pointed at an unexpectedly large asset (e.g. a raw video instead of an image); chunked-transfer origin omitting Content-Length.","solutions":["Raise the REMOTE_FILE_FETCH_MAX_BYTES limit if the file is legitimately large.","Reject oversized URLs upstream (HEAD request first, honor Content-Length) before downloading.","Confirm the fetch `size` option is being honored — upgrade node-fetch if the abort is silently ignored.","Inform the user the file exceeds the configured limit rather than retrying blindly."],"exampleFix":"// before\nconst buffer = await response.buffer();\nif (buffer.length > maxBytes) {\n  throw new Error(`Remote file response too large: ${buffer.length} bytes`);\n}\n\n// after\nconst stated = Number(response.headers.get('content-length'));\nif (stated && stated > maxBytes) {\n  throw new Error(`Remote file too large: ${stated} bytes (limit ${maxBytes})`);\n}\nconst buffer = await response.buffer();\nif (buffer.length > maxBytes) {\n  throw new Error(`Remote file response too large: ${buffer.length} bytes`);\n}","handlingStrategy":"validation","validationCode":"// Honor Content-Length before buffering\nconst stated = Number(response.headers.get('content-length'));\nconst maxBytes = getRemoteFileFetchMaxBytes();\nif (stated && stated > maxBytes) {\n  throw new Error(`Remote file too large (preflight): ${stated} > ${maxBytes}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await saveURLToAzure({ userId, URL, fileName });\n} catch (err) {\n  if (/Remote file response too large/.test(err.message)) {\n    return res.status(413).json({ message: 'File exceeds the remote fetch size limit' });\n  }\n  throw err;\n}","preventionTips":["Set REMOTE_FILE_FETCH_MAX_BYTES to a value that fits both your origin assets and your Azure limits.","HEAD-check Content-Length upstream to reject before downloading.","Reject oversized uploads at the client side before they reach the server."],"tags":["storage","azure","limits","remote-fetch"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}