#10721: fix for matrix media: destructure downloadContent return value in media handler
channel: matrix
stale
Cluster:
Matrix Media Handling Fixes
`MatrixClient.downloadContent()` returns `{ data: Buffer, contentType: string }`, not a raw Buffer.
The old code called `Buffer.from()` on the wrapper object, which threw a `TypeError` on every media download.
The error was silently caught, leaving media as null — so the bot only received the text fallback body (e.g. "Voice message") instead of the actual media file.
Tested in Element X with voice messages on a live Matrix instance.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
- Fixes Matrix media downloads by correctly destructuring `MatrixClient.downloadContent()` to get the `data` `Buffer` instead of treating the wrapper object as a `Buffer`.
- Enforces the configured max size check against the downloaded buffer, preventing oversized media from being saved.
- Preserves/propagates the server-provided content type (`contentType` → `headerType`) into the media save path so downstream handling can infer MIME type correctly.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The change is small, localized, and directly fixes a concrete runtime error path by aligning with the actual `downloadContent()` return shape; it preserves existing control flow and error handling while improving MIME type propagation.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#10313: fix(matrix): fallback to authenticated media download (Matrix v1.11+)
by iter-next · 2026-02-06
83.3%
#8852: fix(matrix): Await mxcToHttp to properly detect authenticated media...
by emadomedher · 2026-02-04
78.2%
#22389: Fix: Matrix plugin not sending images from content blocks
by fryccerGit · 2026-02-21
77.1%
#11443: LINE: fix buffer guards in detectContentType + add tests
by MdRahmatUllah · 2026-02-07
76.2%
#14227: fix(matrix): pass asVoice to audioAsVoice for native voice messages
by tfm-neo-ai · 2026-02-11
75.0%
#20278: Fix/matrix missing bot sdk dependency
by saurav470 · 2026-02-18
74.1%
#10902: fix(msteams): fix inline pasted image downloads
by jlian · 2026-02-07
73.4%
#7845: Fix Matrix mention detection with URL-encoded user IDs
by emadomedher · 2026-02-03
73.3%
#16940: fix(matrix): send voice messages as native voice bubbles
by zerone0x · 2026-02-15
73.1%
#14996: feat(matrix): pass asVoice flag through message tool and add wavefo...
by mauldus · 2026-02-12
73.0%