{"record":{"id":"2ce534156877c602","repo":"Mintplex-Labs/anything-llm","slug":"invalid-image-upload-err-message","errorCode":null,"errorMessage":"Invalid image upload. ${err.message}","messagePattern":"Invalid image upload\\. (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/utils/files/multer.js","lineNumber":214,"sourceCode":"}\n\n/**\n * Handle in-memory image upload for image generation/editing. Buffers are\n * passed directly to the image generation provider, never persisted to disk.\n */\nfunction handleImageGenUpload(request, response, next) {\n  const upload = multer({\n    storage: multer.memoryStorage(),\n    limits: { fileSize: 25 * 1024 * 1024 },\n    fileFilter: (_req, file, cb) => {\n      if (!file.mimetype?.startsWith(\"image/\"))\n        return cb(new Error(\"Only image uploads are allowed.\"));\n      cb(null, true);\n    },\n  }).array(\"image_references\", 10);\n  upload(request, response, function (err) {\n    if (err) {\n      return response.status(500).json({\n        success: false,\n        error: `Invalid image upload. ${err.message}`,\n      });\n    }\n    next();\n  });\n}\n\nmodule.exports = {\n  handleFileUpload,\n  handleAPIFileUpload,\n  handleAssetUpload,\n  handlePfpUpload,\n  handleAudioUpload,\n  handleImageGenUpload,\n};\n","sourceCodeStart":196,"sourceCodeEnd":231,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/files/multer.js#L196-L231","documentation":"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>'.","triggerScenarios":"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.'.","commonSituations":"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'.","solutions":["Append every image under the field name 'image_references' (not 'image', 'images', 'files')","Cap the batch at 10 files per request","Keep each file under 25MB — resize/downscale oversized screenshots","Ensure each part's mimetype starts with 'image/' (set explicit Blob type when constructing from raw buffers)"],"exampleFix":"// before\nimages.forEach((img) => fd.append('images', img)); // wrong part name\n\n// after\nimages.slice(0, 10).forEach((img) => fd.append('image_references', img));","handlingStrategy":"validation","validationCode":"const MAX = 25 * 1024 * 1024;\nconst ok = files.length <= 10 && files.every((f) => f.type.startsWith('image/') && f.size <= MAX);\nif (!ok) throw new Error('Need <=10 images, each image/*, each <=25MB');\nconst fd = new FormData();\nfiles.forEach((f) => fd.append('image_references', f));","typeGuard":"const isImageRefBatch = (files) =>\n  Array.isArray(files) &&\n  files.length <= 10 &&\n  files.every((f) => f instanceof File && f.type.startsWith('image/') && f.size <= 25 * 1024 * 1024);","tryCatchPattern":"if (!res.ok) {\n  const { error } = await res.json();\n  if (/Only image uploads/.test(error)) filterNonImages();\n  if (/too large|Unexpected file|files/.test(error)) splitBatchOrResize();\n}","preventionTips":["Enforce the 10-file cap in the picker UI","Downscale screenshots before adding as references","Name the part 'image_references' in the single shared uploader helper"],"tags":["multer","image-upload","multipart","file-size-limit","image-generation"],"backgroundTag":"multipart-upload-rejected","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}