t29mato Claude Opus 4.6 commited on
Commit
dcb3491
·
1 Parent(s): ced277b

Fix base64 data URI detection: use startsWith instead of comma check

Browse files

The previous "," check could incorrectly split raw base64 strings.
Added debug logging for base64 decode troubleshooting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. api_server.py +2 -1
api_server.py CHANGED
@@ -328,9 +328,10 @@ def digitize_chart(
328
  # Accept both PIL Image and base64 string
329
  if isinstance(image, str):
330
  # Strip data URI prefix if present (e.g. "data:image/png;base64,...")
331
- if "," in image:
332
  image = image.split(",", 1)[1]
333
  img_bytes = base64.b64decode(image)
 
334
  pil_img = Image.open(io.BytesIO(img_bytes)).convert("RGB")
335
  img_rgb = np.array(pil_img)
336
  else:
 
328
  # Accept both PIL Image and base64 string
329
  if isinstance(image, str):
330
  # Strip data URI prefix if present (e.g. "data:image/png;base64,...")
331
+ if image.startswith("data:"):
332
  image = image.split(",", 1)[1]
333
  img_bytes = base64.b64decode(image)
334
+ print(f" Base64 decoded: {len(img_bytes)} bytes, first 4 bytes: {img_bytes[:4]}")
335
  pil_img = Image.open(io.BytesIO(img_bytes)).convert("RGB")
336
  img_rgb = np.array(pil_img)
337
  else: