{"record":{"id":"b5ee381ca8dfa3ba","repo":"PrefectHQ/fastmcp","slug":"file-f-get-name-r-exceeds-max-size-fo","errorCode":null,"errorMessage":"File {f.get('name', '?')!r} exceeds max size ({_format_size(actual_size)} > {_format_size(provider._max_file_size)})","messagePattern":"File (.+?) exceeds max size \\((.+?) > (.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/apps/file_upload.py","lineNumber":290,"sourceCode":"            result[\"content_base64\"] = entry[\"data\"][:200] + \"...\"\n        return result\n\n    # ------------------------------------------------------------------\n    # Tool registration\n    # ------------------------------------------------------------------\n\n    def _register_tools(self) -> None:\n        provider = self\n\n        @self.tool()\n        def store_files(files: list[dict], ctx: Context) -> list[dict]:\n            \"\"\"Store uploaded files. Receives file objects with name, size, type, data (base64).\"\"\"\n            for f in files:\n                # Compute actual data size from the base64 payload rather\n                # than trusting the client-reported ``size`` field.\n                actual_size = _b64_decoded_size(f.get(\"data\", \"\"))\n                if actual_size > provider._max_file_size:\n                    raise ValueError(\n                        f\"File {f.get('name', '?')!r} exceeds max size \"\n                        f\"({_format_size(actual_size)} > \"\n                        f\"{_format_size(provider._max_file_size)})\"\n                    )\n            return provider.on_store(files, ctx)\n\n        @self.tool(model=True)\n        def list_files(ctx: Context) -> list[dict]:\n            \"\"\"List all uploaded files with metadata.\"\"\"\n            return provider.on_list(ctx)\n\n        @self.tool(model=True)\n        def read_file(name: str, ctx: Context) -> dict:\n            \"\"\"Read an uploaded file's contents by name.\"\"\"\n            return provider.on_read(name, ctx)\n\n        @self.ui()\n        def file_manager(ctx: Context) -> PrefabApp:","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/apps/file_upload.py#L272-L308","documentation":"When files are uploaded, store_files computes the real size from the base64 payload (not the client-reported size) and rejects any file larger than the provider's configured _max_file_size with this ValueError. This guards memory and storage from oversized uploads.","triggerScenarios":"Uploading a file whose decoded byte size exceeds provider._max_file_size to the FileUpload app's store tool.","commonSituations":"Users uploading large documents/images; the app configured with a small max_file_size; a client lying about the `size` field (the real base64-derived size is checked).","solutions":["Reduce the file size before uploading (compress, crop, or split the file).","Raise the configured max_file_size on the FileUpload provider if policy allows.","Check the size limit client-side before uploading to give users early feedback."],"exampleFix":"// before\nFileUpload(max_file_size=1_000_000)\n# uploading a 5 MB file fails\n// after\nFileUpload(max_file_size=10_000_000)  # or compress the file to < 1 MB","handlingStrategy":"validation","validationCode":"import base64, os\nMAX = provider_max_file_size\nif os.path.getsize(path) > MAX:\n    raise ValueError(f\"{path} exceeds {MAX} bytes; compress or split before upload\")\ndata = base64.b64encode(open(path, 'rb').read()).decode()\nif _b64_decoded_size(data) > MAX:\n    raise ValueError(\"decoded payload still exceeds limit\")","typeGuard":null,"tryCatchPattern":"try:\n    store_upload(files)\nexcept ValueError as e:\n    if \"exceeds max size\" in str(e):\n        compress_and_retry(files, target=max_file_size)","preventionTips":["Check file size client-side before upload","Configure max_file_size to match real user needs","Compress large files (zip, image downscale) before upload","Remember the limit is enforced on the base64-decoded size, not the client-reported size"],"tags":["python","valueerror","file-upload","size-limit"],"backgroundTag":"upload-size-limit-exceeded","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}