title: whatsapp-web.js how save downloadMedia()
body: <p><strong>Hi, I'm new to this and I have a question that breaks my head,
  I'm using whatsapp-web.js 1.12.6, but when I download a multimedia file I can't find how to save it ...
  I am trying to do with fs.writefile, but it throws me an error
  How to save that object as a file?</strong></p>
  <pre><code>const listenMessage = () =&gt; {
        client.on(&quot;message&quot;, async (inboundMsg) =&gt; {
          console.log(inboundMsg);
      
          const { from, to, body, hasMedia, mediaKey } = inboundMsg;
      
          if (hasMedia) {
            const mediafile = await inboundMsg.downloadMedia();
            console.log(
              mediafile.mimetype,
              mediafile.filename,
              mediafile.data.length
            );
              
            //How to save that object as a file? =====================================
      
            fs.writeFile('./upload/', JSON.stringify(mediafile.data), function (err) {
              if (err) {
                console.log(err);
              }
            });
      
            //========================================================================
      
      
            var post = {
              message: body,
              direction: &quot;inbound&quot;,
              number: from,
              media: &quot;mymediafile&quot;,
            };
            var query = pool.query(
              &quot;INSERT INTO chat SET ?&quot;,
              post,
              function (error, results, fields) {
                if (error) throw error;
                console.log(from, to, body, hasMedia);
              }
            );
          } else {
            var post = {
              message: body,
              direction: &quot;inbound&quot;,
              number: from,
            };
            var query = pool.query(
              &quot;INSERT INTO chat SET ?&quot;,
              post,
              function (error, results, fields) {
                if (error) throw error;
                console.log(from, to, body);
              }
            );
          }
        });
      };
  </code></pre>