pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.05k stars 3.59k forks source link

Download file Media - Not working! #463

Closed IgalNeeman closed 3 years ago

IgalNeeman commented 3 years ago

hello, if i send my file cv to the bot its not working , not with: !mediainfo its not downloading the file.

in the file Example.js:

else if (msg.body === "!mediainfo" && msg.hasMedia)
{
    const attachmentData = await msg.downloadMedia();
    await msg.reply(`
        *Media info*
        MimeType: ${attachmentData.mimetype}
        Filename: ${attachmentData.filename}
        Data (length): ${attachmentData.data.length}
    `);
} 

its not working...

CONSOLE.LOG:

MESSAGE RECEIVED Message { mediaKey: 'KPgPZnfFJzES0eWHBxhq/X/HSQ7i1migfIMYE4Wn/8Q=', id: { fromMe: false, remote: '972526020093@c.us', id: '3EB097F05C684A2516D8', _serialized: 'false_972526020093@c.us_3EB097F05C684A2516D8' }, ack: -1, hasMedia: true, body: 'igal-n - old.pdf', type: 'document', timestamp: 1606842562, from: '972526020093@c.us', to: '972527972028@c.us', author: undefined, isForwarded: false, isStatus: false, broadcast: false, fromMe: false, hasQuotedMsg: false, location: undefined, vCards: [], mentionedIds: [] }

where is the file Downloaded? if yes? and how can i use it ? thank you

IgalNeeman commented 3 years ago

its worked its ok. sorry.

KiroFyzu commented 2 years ago

its worked its ok. sorry.

bro 🗿🗿

ycodexme commented 8 months ago

Guys please help me, I tried to set up this module used to download the pdf file sent by the user and save it in the specific folder while keeping the same name of this document but once the process of uploading download the pdf document completed I find that the pdf file is wrong. I'm sending you screenshots of the process:

else if (msg.body === '!mediainfo' && msg.hasMedia) { const attachmentData = await msg.downloadMedia(); msg.reply( *Media info* MimeType: ${attachmentData.mimetype} Filename: ${attachmentData.filename} Data (length): ${attachmentData.data.length} );

    try {
        // Download the media (PDF file) and save it to the ./document folder
        const mediaBuffer = await msg.downloadMedia();
        const filePath = ./document/${attachmentData.filename};

        // Write the buffer to a file
        fs.writeFileSync(filePath, mediaBuffer.data);

        console.log(Media downloaded and saved to: ${filePath});
    } catch (error) {
        console.error('Error saving the PDF file:', error);
        msg.reply('An error occurred while saving the PDF file.');

IMG_20231224_135459_554 IMG_20231224_135449_555 IMG_20231224_135454_183 IMG_20231224_135457_168

bhishmakajaria commented 5 months ago

@ycodexme : please use this

https://www.npmjs.com/package/@open-wa/wa-decrypt?activeTab=readme

It works perfect.