← Back to PRs

#17842: Fix Google Chat media upload failure by inferring content-type from filename

by Clawborn open 2026-02-16 07:07 View on GitHub →
channel: googlechat stale size: S trusted-contributor
## 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