[PR #2934] fix: base64-encode binary files in /file/content endpoint #10490

Closed
opened 2026-02-16 18:15:09 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/2934

State: closed
Merged: No


Binary files were being corrupted when returned as JSON strings because the server converted binary data to UTF-8, replacing invalid UTF-8 bytes with replacement characters (�). This made images and other binary files unreadable in the web interface.

Changes:

  • Add 'encoding' field to File.Content schema (utf8 | base64)
  • Implement isBinaryFile() to detect binary files by extension and null bytes
  • Base64-encode binary files before JSON serialization
  • Return encoding type in API response for proper client-side decoding

This eliminates the need for client-side filesystem workarounds and properly supports all binary file types (images, PDFs, executables, etc.)

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/2934 **State:** closed **Merged:** No --- Binary files were being corrupted when returned as JSON strings because the server converted binary data to UTF-8, replacing invalid UTF-8 bytes with replacement characters (�). This made images and other binary files unreadable in the web interface. Changes: - Add 'encoding' field to File.Content schema (utf8 | base64) - Implement isBinaryFile() to detect binary files by extension and null bytes - Base64-encode binary files before JSON serialization - Return encoding type in API response for proper client-side decoding This eliminates the need for client-side filesystem workarounds and properly supports all binary file types (images, PDFs, executables, etc.)
yindo added the pull-request label 2026-02-16 18:15:09 -05:00
yindo closed this issue 2026-02-16 18:15:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10490