{"record":{"id":"c8095792815283d5","repo":"odysseus-dev/odysseus","slug":"no-image-provided","errorCode":null,"errorMessage":"No image provided","messagePattern":"No image provided","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"routes/gallery/gallery_routes.py","lineNumber":449,"sourceCode":"            db.close()\n\n    # ---- POST /api/gallery/{id}/replace ----\n    @router.post(\"/api/gallery/{image_id}/replace\")\n    async def gallery_replace(request: Request, image_id: str):\n        \"\"\"Replace an existing gallery image file with a new one.\"\"\"\n        user = get_current_user(request)\n        db = SessionLocal()\n        try:\n            img = db.query(GalleryImage).filter(GalleryImage.id == image_id).first()\n            if not img:\n                raise HTTPException(404, \"Image not found\")\n            if not user or img.owner != user:\n                raise HTTPException(403, \"Not your image\")\n\n            form = await request.form()\n            file = form.get(\"image\")\n            if not file or not hasattr(file, 'read'):\n                raise HTTPException(400, \"No image provided\")\n\n            content = await read_upload_limited(file, GALLERY_UPLOAD_MAX_BYTES, \"Gallery replacement\")\n            GALLERY_IMAGE_DIR.mkdir(parents=True, exist_ok=True)\n            img_path = _gallery_image_path(img.filename)\n            img_path.write_bytes(content)\n\n            # Refresh dimensions in case the editor resized the canvas.\n            # updated_at auto-bumps via TimestampMixin's onupdate hook.\n            try:\n                from PIL import Image\n                from io import BytesIO\n                with Image.open(BytesIO(content)) as new_im:\n                    img.width = new_im.width\n                    img.height = new_im.height\n            except Exception:\n                pass\n            try:\n                db.commit()","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/routes/gallery/gallery_routes.py#L431-L467","documentation":"HTTP 400 raised by POST /api/gallery/{image_id}/replace when the multipart form has no usable file. The handler requires a form field named 'image' that is a file-like object (has a .read attribute). A missing field, a plain text form value, or a non-multipart body all fail the check `not file or not hasattr(file, 'read')`.","triggerScenarios":"POSTing JSON instead of multipart/form-data; submitting the form with the file input left empty; naming the part 'file' or 'imageFile' instead of 'image'; sending a string value in the 'image' field.","commonSituations":"Frontend FormData built with the wrong field name; file input not required in the UI so users submit empty; curl invocations missing -F 'image=@path'; test clients sending urlencoded bodies.","solutions":["Send multipart/form-data with a file part named exactly 'image'.","Make the file input required client-side before submitting.","For curl: curl -F 'image=@new.png' .../replace.","Check no proxy or body-parsing middleware strips multipart bodies."],"exampleFix":"// before\nconst fd = new FormData(); fd.append('file', blob); // wrong field name -> 400\n// after\nconst fd = new FormData(); fd.append('image', blob, 'edit.png');","handlingStrategy":"validation","validationCode":"if (!(blob instanceof Blob) || blob.size === 0) return showError('Select an image');\nconst fd = new FormData(); fd.append('image', blob, 'edit.png');","typeGuard":"const isFilePart = (v) => v != null && typeof v.read === 'function'; // server-side shape","tryCatchPattern":"try { await fetch(url, {method:'POST', body: fd}); } catch (e) { if (e.status === 400) showError('Attach an image file in the \"image\" field'); }","preventionTips":["Always append the file under the exact key 'image'","Disable submit until a file is chosen","Send multipart/form-data, never JSON, for upload endpoints"],"tags":["http","validation","upload","multipart","gallery"],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}