Skip to content

Conversation

@nem035
Copy link

@nem035 nem035 commented Dec 23, 2025

Summary

Fixes image detection when dragging/pasting file paths with uppercase extensions (e.g., .PNG, .JPG) from Finder on macOS.

I airdropped these screenshots from my phone and dragging the to OpenCode doesn't work:

Screenshot 2025-12-22 at 10 04 46 PM

Problem

Bun.file() only recognizes lowercase file extensions for MIME type detection. When you drag an image from Finder that has an uppercase extension like /Users/nem035/Downloads/IMG_8048.PNG, Bun returns application/octet-stream instead of image/png:

Bun.file('/test.png').type  // "image/png" ✓
Bun.file('/test.PNG').type  // "application/octet-stream" ✗

This caused pasted image paths to not be recognized as images, so they would be treated as plain text instead of showing the [Image 1] yellow UI indicator.

Solution

Added a helper function that extracts the file extension, normalizes it to lowercase, and looks up the correct MIME type from a known list of image extensions. This is used as the primary source for MIME type detection, with Bun.file().type as a fallback for other file types.

Before After
Screenshot 2025-12-22 at 10 24 09 PM Screenshot 2025-12-22 at 10 24 18 PM

Bun.file() only recognizes lowercase file extensions for MIME type detection.
When dragging images from Finder on macOS, files often have uppercase extensions
like .PNG or .JPG, which causes Bun to return 'application/octet-stream' instead
of the correct image MIME type.

This meant pasted image paths were not recognized as images and wouldn't display
the [Image 1] UI indicator.

The fix adds a helper function that extracts the file extension, normalizes it
to lowercase, and looks up the correct MIME type from a known list of image
extensions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant