#17842: Fix Google Chat media upload failure by inferring content-type from filename
channel: googlechat
stale
size: S
trusted-contributor
Cluster:
Attachment Processing Enhancements
## Description
Google Chat API requires correct `image/*` Content-Type for image attachments to be rendered inline. If `contentType` was missing (e.g. download failed to detect it or URL lacked extension), the upload defaulted to `application/octet-stream`, causing images to appear as file downloads or fail validation.
## Fix
Fallback to inferring MIME type from filename extension in `uploadGoogleChatAttachment` if `contentType` is not explicitly provided.
## Tests
Added `extensions/googlechat/src/api.upload-content-type.test.ts` verifying:
- Explicit contentType is respected
- Missing contentType is inferred from filename (jpg/png/etc)
- Defaults to octet-stream for unknown extensions
## AI Transparency
- **Assisted by**: OpenClaw Agent (Claude 3.5 Sonnet / Opus)
- **Testing level**: Fully tested with new unit tests (`extensions/googlechat/src/api.upload-content-type.test.ts`)
- **Prompt strategy**: Self-correction loop based on codebase analysis
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds a MIME type inference fallback to `uploadGoogleChatAttachment` so that when `contentType` is not provided by the caller, the function infers it from the filename extension before falling back to `application/octet-stream`. This fixes Google Chat image attachments appearing as generic file downloads when the upstream media fetch didn't detect a content type.
- Added `lookupMimeFromExtension()` helper mapping common extensions (`.jpg`, `.jpeg`, `.png`, `.gif`, `.webp`, `.mp4`, `.pdf`) to MIME types
- Modified `uploadGoogleChatAttachment` to use a three-step resolution: explicit `contentType` → inferred from filename → `application/octet-stream`
- New test file validates all three fallback tiers
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it adds a sensible fallback for content-type detection with no risk to existing behavior.
- The code change is small, focused, and low-risk. The nullish coalescing chain preserves the existing behavior when `contentType` is explicitly provided, and only adds inference as a new fallback. The `lookupMimeFromExtension` helper is straightforward. The test mock account has shape issues flagged in prior threads, but the core logic is sound. Score of 4 rather than 5 because the prior thread notes about the mock account validity and the "attachment" filename edge case remain unresolved.
- The test file `extensions/googlechat/src/api.upload-content-type.test.ts` has a mock account with an invalid shape (flagged in prior review).
<sub>Last reviewed commit: 2617d88</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22113: feat: support non-image file attachments in webchat chat.send
by Kt-L · 2026-02-20
77.0%
#14940: fix(googlechat): convert Markdown formatting to Google Chat markup
by brandonwise · 2026-02-12
75.7%
#22781: fix(webchat): persist chat attachments after guards and expose medi...
by Kansodata · 2026-02-21
75.6%
#10441: webchat: switch file uploads to HTTP /uploads
by supernewbilityxht1 · 2026-02-06
75.2%
#8284: Fix: Webchat images now persist after sending
by vishaltandale00 · 2026-02-03
75.1%
#3727: fix(googlechat): space type detection for modern API
by gustavozirbes · 2026-01-29
74.6%
#11443: LINE: fix buffer guards in detectContentType + add tests
by MdRahmatUllah · 2026-02-07
74.6%
#11160: Media: add missing audio MIME-to-extension mappings (aac, flac, opu...
by lailoo · 2026-02-07
73.6%
#16346: feat: support image attachments in OpenAI chat completions endpoint
by sh1nj1 · 2026-02-14
73.2%
#4327: Gateway Web Chat: add image/file upload (attach, drag-drop, paste)
by RogerHsu7 · 2026-01-30
73.0%