Mintplex-Labs/anything-llm · error · Error

Error uploading pfp.

Error message

Error uploading pfp.

What it means

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.

Source

Thrown at frontend/src/models/system.js:310

    return await fetch(`${API_BASE}/system/remove-folder`, {
      method: "DELETE",
      headers: baseHeaders(),
      body: JSON.stringify({ name }),
    })
      .then((res) => res.ok)
      .catch((e) => {
        console.error(e);
        return false;
      });
  },
  uploadPfp: async function (formData) {
    return await fetch(`${API_BASE}/system/upload-pfp`, {
      method: "POST",
      body: formData,
      headers: baseHeaders(),
    })
      .then((res) => {
        if (!res.ok) throw new Error("Error uploading pfp.");
        return { success: true, error: null };
      })
      .catch((e) => {
        console.log(e);
        return { success: false, error: e.message };
      });
  },
  uploadLogo: async function (formData) {
    return await fetch(`${API_BASE}/system/upload-logo`, {
      method: "POST",
      body: formData,
      headers: baseHeaders(),
    })
      .then((res) => {
        if (!res.ok) throw new Error("Error uploading logo.");
        return { success: true, error: null };
      })
      .catch((e) => {

View on GitHub (pinned to 526360e320)

Solutions

  1. Raise the reverse proxy body-size limit (e.g. client_max_body_size) above the avatar size.
  2. Ensure no interceptor sets Content-Type on the FormData request — let the browser set it.
  3. Confirm localStorage AUTH_TOKEN is present (baseHeaders is sent).
  4. Validate the file is an image and within the documented size before uploading.

Example fix

// before
const fd = new FormData(); fd.append("file", file);
await System.uploadPfp(fd);

// after (client-side size/type guard)
if (!file.type.startsWith("image/")) return setError("Image only");
if (file.size > 2_000_000) return setError("Max 2MB");
const fd = new FormData(); fd.append("file", file);
const res = await System.uploadPfp(fd);
if (!res.success) setError(res.error);
Defensive patterns

Strategy: validation

Validate before calling

function validPfpUpload(file) {
  return file instanceof File && file.type.startsWith("image/") && file.size <= 2_000_000;
}

Type guard

/** @param {any} r @returns {r is {success:boolean, error:string|null}} */
function isUploadResult(r) { return r != null && typeof r.success === "boolean"; }

Try / catch

if (!validPfpUpload(file)) { setError("Pick an image under 2MB"); return; }
const res = await System.uploadPfp(fd);
if (!isUploadResult(res) || !res.success) setError(res.error);

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/fd45c8e782585752. Report an issue: GitHub.