🪲 BUG-#3: Fix image attachments always sent as image/png - #15
Conversation
FernandoCelmer
left a comment
There was a problem hiding this comment.
The fix is clean and correct.
Root cause addressed: addPendingImageFile was stripping the data:<mime>;base64, prefix via .split(',')[1], causing downstream code to reconstruct it with a hardcoded image/png MIME type. The PR removes that stripping at the source and propagates the full data URL throughout, which is the right approach.
Backward compatibility: The ternary in addUserTurn (image.startsWith('data:') ? image : 'data:image/png;base64,' + image) correctly handles sessions persisted before this fix -- bare base64 strings still render as PNG, matching old behavior.
Guard correctness: dataUrl.startsWith('data:') is a reasonable guard since FileReader.readAsDataURL() always returns a data URL per spec; it is semantically tighter than the previous truthiness check and safe.
No blocking issues found. Changes are minimal, focused, and consistent with the described fix.
Description
Fix image attachments always being sent as
image/pngregardless of actual MIME type.addPendingImageFile()was stripping thedata:<mime>;base64,prefix fromFileReader.readAsDataURL()'s result, keeping only the bare base64. Both the attachment preview andaddUserTurn's history rendering then hardcodeddata:image/png;base64,when reconstructing it. JPEG/GIF/WebP attachments were mislabeled as PNG everywhere, including in theimagesarray forwarded topycodeloop serve.Now the full data URL (real MIME included) is kept end to end — pushed into
pendingImagesas-is, used directly asimg.src, and sent throughsendPrompt'simagesarray unchanged.addUserTurnstill accepts a bare base64 string (assumes PNG) for sessions saved before this fix.Motivation and Context
Closes #3
Paired with dotflow-io/pycodeloop#12 — pycodeloop's own
_shapes.pyalso hardcodedimage/pngin the outgoing API request, so both sides needed the fix for it to work end to end.Types of changes
Checklist
Test plan
npm test(37 passed) /npx tsc --noEmit/npm run lintclean