{"record":{"id":"fd45c8e782585752","repo":"Mintplex-Labs/anything-llm","slug":"error-uploading-pfp","errorCode":null,"errorMessage":"Error uploading pfp.","messagePattern":"Error uploading pfp\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/models/system.js","lineNumber":310,"sourceCode":"    return await fetch(`${API_BASE}/system/remove-folder`, {\n      method: \"DELETE\",\n      headers: baseHeaders(),\n      body: JSON.stringify({ name }),\n    })\n      .then((res) => res.ok)\n      .catch((e) => {\n        console.error(e);\n        return false;\n      });\n  },\n  uploadPfp: async function (formData) {\n    return await fetch(`${API_BASE}/system/upload-pfp`, {\n      method: \"POST\",\n      body: formData,\n      headers: baseHeaders(),\n    })\n      .then((res) => {\n        if (!res.ok) throw new Error(\"Error uploading pfp.\");\n        return { success: true, error: null };\n      })\n      .catch((e) => {\n        console.log(e);\n        return { success: false, error: e.message };\n      });\n  },\n  uploadLogo: async function (formData) {\n    return await fetch(`${API_BASE}/system/upload-logo`, {\n      method: \"POST\",\n      body: formData,\n      headers: baseHeaders(),\n    })\n      .then((res) => {\n        if (!res.ok) throw new Error(\"Error uploading logo.\");\n        return { success: true, error: null };\n      })\n      .catch((e) => {","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/system.js#L292-L328","documentation":"Thrown by System.uploadPfp on a non-2xx POST to /api/system/upload-pfp. The body is a FormData object (multipart) and baseHeaders() is passed — note baseHeaders() must NOT set Content-Type here so the browser can set the multipart boundary. The .catch() returns {success:false, error:e.message}; the thrown message is generic and discards the response body.","triggerScenarios":"Calling uploadPfp(formData) when the file exceeds a server/proxy size limit (413), when the MIME type is rejected, when baseHeaders() is misconfigured to include a manual Content-Type that breaks multipart, or when the auth token is rejected (401/403).","commonSituations":"Reverse proxy (nginx client_max_body_size) caps uploads below the file size; the user's token expired before submit; an interceptor added application/json Content-Type to the FormData request.","solutions":["Raise the reverse proxy body-size limit (e.g. client_max_body_size) above the avatar size.","Ensure no interceptor sets Content-Type on the FormData request — let the browser set it.","Confirm localStorage AUTH_TOKEN is present (baseHeaders is sent).","Validate the file is an image and within the documented size before uploading."],"exampleFix":"// before\nconst fd = new FormData(); fd.append(\"file\", file);\nawait System.uploadPfp(fd);\n\n// after (client-side size/type guard)\nif (!file.type.startsWith(\"image/\")) return setError(\"Image only\");\nif (file.size > 2_000_000) return setError(\"Max 2MB\");\nconst fd = new FormData(); fd.append(\"file\", file);\nconst res = await System.uploadPfp(fd);\nif (!res.success) setError(res.error);","handlingStrategy":"validation","validationCode":"function validPfpUpload(file) {\n  return file instanceof File && file.type.startsWith(\"image/\") && file.size <= 2_000_000;\n}","typeGuard":"/** @param {any} r @returns {r is {success:boolean, error:string|null}} */\nfunction isUploadResult(r) { return r != null && typeof r.success === \"boolean\"; }","tryCatchPattern":"if (!validPfpUpload(file)) { setError(\"Pick an image under 2MB\"); return; }\nconst res = await System.uploadPfp(fd);\nif (!isUploadResult(res) || !res.success) setError(res.error);","preventionTips":["Never set Content-Type on FormData requests — let the browser set the boundary.","Validate size/type before uploading.","Ensure the reverse proxy body-size cap exceeds the avatar."],"tags":["network","upload","multipart","profile","auth"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}