[core] NOWEB - use stream mode for media download to fix 0-byte audio files (#1997)

The 'buffer' mode in Baileys' downloadMediaMessage() silently returns
an empty buffer for audio/voice messages (PTT, OGG Opus), while images
download correctly. Switching to 'stream' mode and collecting chunks
manually resolves the issue.

Tested in production (WAHA Plus 2026.3.4, NOWEB engine, S3 storage):
- Before: voice messages saved as 0 bytes in S3
- After: voice messages saved with correct size (58,005 bytes confirmed)

Fixes #1996
This commit is contained in:
Daniel (Danai) Rudaev authored and GitHub committed 2026-04-06 09:51:28 +07:00
1 parent 10e8869903
commit 55f7d4dac7
1 file changed
+11 -3
+11 -3
View File
@@ -2848,9 +2848,12 @@ export class NOWEBEngineMediaProcessor implements IMediaEngineProcessor<any> {
content.url = null;
}
return (await downloadMediaMessage(
// Use 'stream' mode instead of 'buffer' to fix 0-byte audio files
// 'buffer' mode silently returns empty buffer for audio/voice messages
// See: https://github.com/devlikeapro/waha/issues/1996
const stream = await downloadMediaMessage(
message,
'buffer',
'stream',
{},
{
logger: this.logger,
@@ -2859,7 +2862,12 @@ export class NOWEBEngineMediaProcessor implements IMediaEngineProcessor<any> {
).finally(() => {
// Set url back in case we removed it
content.url = url;
})) as Buffer;
});
const chunks: Buffer[] = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
return Buffer.concat(chunks);
}
getFilename(message: any): string | null {