{"record":{"id":"1e435cac7bce36b1","repo":"sgl-project/sglang","slug":"b64-format-hint-missing-base64-marker","errorCode":null,"errorMessage":"{b64_format_hint} (missing ;base64 marker)","messagePattern":"(.+?) \\(missing ;base64 marker\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/utils/image_io.py","lineNumber":19,"sourceCode":"# SPDX-License-Identifier: Apache-2.0\nimport base64\nimport os\nimport re\n\n\ndef save_base64_image_to_path(base64_data: str, target_path: str) -> str:\n    b64_format_hint = (\n        \"Failed to decode base64 image. \"\n        \"Expected format: `data:[<media-type>];base64,<data>`\"\n    )\n\n    match = re.match(r\"data:(.*?)(;base64)?,(.*)\", base64_data)\n    if not match:\n        raise ValueError(b64_format_hint)\n    media_type = match.group(1)\n    is_base64 = match.group(2)\n    if not is_base64:\n        raise ValueError(f\"{b64_format_hint} (missing ;base64 marker)\")\n    data = match.group(3)\n    if not data:\n        raise ValueError(f\"{b64_format_hint} (empty data payload)\")\n\n    if media_type.startswith(\"image/\"):\n        ext = media_type.split(\"/\")[-1].lower()\n        if ext == \"jpeg\":\n            ext = \"jpg\"\n    else:\n        ext = \"jpg\"\n    target_path = f\"{target_path}.{ext}\"\n    os.makedirs(os.path.dirname(target_path), exist_ok=True)\n\n    try:\n        image_data = base64.b64decode(data)\n    except Exception as exc:\n        raise Exception(f\"Failed to decode base64 image: {str(exc)}\") from exc\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/utils/image_io.py#L1-L37","documentation":"The input matched the generic data-URI shape but lacked the ;base64 marker, e.g. data:image/png,.... Only base64-encoded payloads are supported, so the parser rejects URL-encoded or plain data URIs.","triggerScenarios":"Supplying a data URI without ;base64 such as data:image/png,%89PNG... to _maybe_url_image / prepare_warmup_image_path.","commonSituations":"Clients URL-encoding image bytes instead of base64-encoding them; hand-built data URIs that omit the marker.","solutions":["Base64-encode the bytes and include the marker: data:image/png;base64,...","Ensure client libraries (e.g. canvas toDataURL) are used unchanged — they already emit ;base64"],"exampleFix":"// before\nsave_base64_image_to_path(\"data:image/png,%89PNG%0D%0A\", \"/tmp/img\")\n// after\nsave_base64_image_to_path(\"data:image/png;base64,iVBORw0KGgo...\", \"/tmp/img\")","handlingStrategy":"validation","validationCode":"def has_base64_marker(s: str) -> bool:\n    return \";base64,\" in s","typeGuard":"def is_base64_data_uri(s: str) -> bool:\n    return isinstance(s, str) and s.startswith(\"data:\") and \";base64,\" in s","tryCatchPattern":"try:\n    save_base64_image_to_path(uri, path)\nexcept ValueError as e:\n    if \"missing ;base64 marker\" in str(e):\n        uri = uri.replace(\",\", \";base64,\", 1) if uri.startswith(\"data:\") else uri","preventionTips":["Always base64-encode (not URL-encode) image bytes","Pass through browser toDataURL output unchanged"],"tags":["base64","data-uri","image-input","validation"],"backgroundTag":"malformed-base64-data-uri","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}