Skip to content

fix(matrix): handle downloadContent returning {data, contentType} object#11902

Draft
jacoblyles wants to merge 1 commit intoopenclaw:mainfrom
jacoblyles:fix/matrix-media-download
Draft

fix(matrix): handle downloadContent returning {data, contentType} object#11902
jacoblyles wants to merge 1 commit intoopenclaw:mainfrom
jacoblyles:fix/matrix-media-download

Conversation

@jacoblyles
Copy link

Bug

@vector-im/matrix-bot-sdk's downloadContent returns {data: Buffer, contentType: string}, not a raw Buffer. The existing code passed this object directly to Buffer.from(), causing ERR_INVALID_ARG_TYPE for all inbound Matrix media (images, files, audio, video).

Fix

Unwrap the data property from the response before creating the Buffer. Also extracts contentType from the response for proper MIME type detection.

// Before (broken):
const buffer = await params.client.downloadContent(params.mxcUrl);
return { buffer: Buffer.from(buffer) };  // buffer is {data, contentType}, not a Buffer

// After:
const result = await params.client.downloadContent(params.mxcUrl);
const raw = (result as any)?.data ?? result;
const buf = Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
return { buffer: buf, headerType: (result as any)?.contentType };

Testing

Verified on a local Synapse homeserver — images sent from Element iOS now download and are passed to the agent correctly.

The @vector-im/matrix-bot-sdk downloadContent method returns
{data: Buffer, contentType: string} rather than a raw Buffer.
The existing code passed this object directly to Buffer.from(),
causing ERR_INVALID_ARG_TYPE for all inbound Matrix media.

Also extracts contentType from the response header for proper
MIME type detection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments