fix(telegram): accept image files delivered as application/octet-stream - #214
Open
vinceferro wants to merge 1 commit into
Open
fix(telegram): accept image files delivered as application/octet-stream#214vinceferro wants to merge 1 commit into
vinceferro wants to merge 1 commit into
Conversation
iOS 'Send as File' — the highest-quality path for photos — delivers images with mime_type=application/octet-stream and no preview; only the filename extension reveals the type. The document handler rejected these as unsupported documents, so iPhone users could not send images as files at all. Route by extension fallback when the mime is not image/*: detect .jpg/ .jpeg/.png/.webp/.gif, normalize the file part's mime (and data URI prefix) accordingly, and reuse the existing image capability check. Verified end-to-end against a live opencode serve: octet-stream jpg now reaches the model as image/jpeg and gets described correctly. Co-authored-by: opencode x-preview-f-free <noreply@opencode.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On iOS, Send as File is the only way to share a photo at original quality. Telegram delivers it as a document with
mime_type=application/octet-streamand no preview — the filename extension (.jpg) is the only type hint.handleDocumentMessageroutes onmimeType.startsWith("image/")(fast path) or theDOCUMENT_MIME_TYPESallowlist. An octet-stream.jpgmatches neither, so iPhone users get the unsupported-document reply and cannot send images as files at all.Repro
Fix
When mime is not
image/*, fall back to the filename extension (.jpg/.jpeg/.png/.webp/.gif). If it looks like an image: normalize the file part'smimeand data-URI prefix to the real type, and reuse the existing image-input capability check. Documents with properimage/*mimes keep the existing path unchanged.Verification
Tested end-to-end against a live opencode serve with an octet-stream-delivered jpg:
image/jpeg, model describes the image correctlyHappy to adjust the extension list or move the fallback into the existing fast-path branch if maintainers prefer that shape.