Mintplex-Labs/anything-llm · error

Invalid image upload. ${err.message}

Error message

Invalid image upload. ${err.message}

What it means

Error from the in-memory image-upload middleware for image generation/editing references. It configures multer with memoryStorage, a per-file 25MB limit, a fileFilter requiring mimetype 'image/*', and .array('image_references', 10) — i.e. up to 10 files all under the field name 'image_references'. Buffers are passed to the image provider, never persisted. Any violation returns HTTP 500 with 'Invalid image upload. <err.message>'.

Source

Thrown at server/utils/files/multer.js:214

}

/**
 * Handle in-memory image upload for image generation/editing. Buffers are
 * passed directly to the image generation provider, never persisted to disk.
 */
function handleImageGenUpload(request, response, next) {
  const upload = multer({
    storage: multer.memoryStorage(),
    limits: { fileSize: 25 * 1024 * 1024 },
    fileFilter: (_req, file, cb) => {
      if (!file.mimetype?.startsWith("image/"))
        return cb(new Error("Only image uploads are allowed."));
      cb(null, true);
    },
  }).array("image_references", 10);
  upload(request, response, function (err) {
    if (err) {
      return response.status(500).json({
        success: false,
        error: `Invalid image upload. ${err.message}`,
      });
    }
    next();
  });
}

module.exports = {
  handleFileUpload,
  handleAPIFileUpload,
  handleAssetUpload,
  handlePfpUpload,
  handleAudioUpload,
  handleImageGenUpload,
};

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Append every image under the field name 'image_references' (not 'image', 'images', 'files')
  2. Cap the batch at 10 files per request
  3. Keep each file under 25MB — resize/downscale oversized screenshots
  4. Ensure each part's mimetype starts with 'image/' (set explicit Blob type when constructing from raw buffers)

Example fix

// before
images.forEach((img) => fd.append('images', img)); // wrong part name

// after
images.slice(0, 10).forEach((img) => fd.append('image_references', img));
Defensive patterns

Strategy: validation

Validate before calling

const MAX = 25 * 1024 * 1024;
const ok = files.length <= 10 && files.every((f) => f.type.startsWith('image/') && f.size <= MAX);
if (!ok) throw new Error('Need <=10 images, each image/*, each <=25MB');
const fd = new FormData();
files.forEach((f) => fd.append('image_references', f));

Type guard

const isImageRefBatch = (files) =>
  Array.isArray(files) &&
  files.length <= 10 &&
  files.every((f) => f instanceof File && f.type.startsWith('image/') && f.size <= 25 * 1024 * 1024);

Try / catch

if (!res.ok) {
  const { error } = await res.json();
  if (/Only image uploads/.test(error)) filterNonImages();
  if (/too large|Unexpected file|files/.test(error)) splitBatchOrResize();
}

Prevention

When it happens

Trigger: POST multipart with files under part names other than 'image_references'; more than 10 file parts (LIMIT_FILE_COUNT / LIMIT_UNEXPECTED_FILE); any single image over 25MB (LIMIT_FILE_SIZE, the cap is per-file); a part whose mimetype is not image/* (e.g. application/pdf or video/*) triggering 'Only image uploads are allowed.'.

Common situations: Sending 12 reference images at once; attaching a PDF page or screenshot saved with an odd mimetype; HEIC files reported as image/heic usually pass, but downloaded blobs with application/octet-stream mimetype fail; reusing an uploader that names parts 'images' or 'files'.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/2ce534156877c602. Report an issue: GitHub.