fix: detect LocalImage MIME type across native gateways#430
Merged
pushpak1300 merged 7 commits intoApr 23, 2026
Conversation
pushpak1300
reviewed
Apr 20, 2026
pushpak1300
requested changes
Apr 20, 2026
eff0168 to
017af53
Compare
Mirror the OpenAI fix across the other native gateways that still read $attachment->mime directly on LocalImage. Extract fakePngFile() into tests/Helpers.php so the three provider tests share one PNG fixture.
Adds Image::dataUriMimeType() with a single DEFAULT_MIME_TYPE constant, replacing 12 duplicated "$attachment->mimeType() ?? 'image/png'" expressions across 7 gateways. Also covers the StoredImage arms in OpenAI and Xai that previously hardcoded data:image/png;base64.
Contributor
Author
|
@pushpak1300 while I was in here I noticed Or the slightly longer version if you want to mention the MIME fallback too: While reviewing this I noticed the |
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.
Three native gateways (OpenAI, xAI, Gemini) read
$attachment->mimedirectly when mapping aLocalImage. That property is nullable —LocalImage::__constructaccepts?string $mimeType = null— so if you don't pass a MIME explicitly, the outgoing request is malformed:data:;base64,<payload>(rejected as invalidinput_image)inlineData.mimeType: nullThe other gateways (OpenRouter, Groq, Mistral, DeepSeek, Anthropic) already go through
$attachment->mimeType(), which falls back toFilesystem::mimeType($path)for auto-detection. This PR switches the three outliers to the same call, with an?? 'image/png'guard for the edgecase where detection also returns null.
While here, I pulled that
mimeType() ?? 'image/png'fallback up toImage::dataUriMimeType()since it was duplicated across every image arm in allseven gateways.
Added one regression test per affected gateway — each constructs a
LocalImagewithout a MIME and asserts the outgoing request carriesimage/png.All three fail on
mainand pass with the fix.