0

I have a function in node.js that adds a file to IPFS, takes the hash and ggives it to a function to generate qrcode using the hash. But my qrcode is being produced before the file is uploaded, and await is not helping.

Please help!

await ipfs.files.add(testBuffer, function (err, file) {
        if (err) {
          console.log(err);
        }
        {filehash=file;
        console.log(filehash);
        console.log("printed filehash");
        
      }})

      const qrcodepic= await qr.generateQRCode(filehash,EmpName,EmpId,IDate);

      console.log(qrcodepic);
      return qrcodepic;
  • `ipfs.files.add` isn't a function. If you mean `ipfs.add` then I still don't know what you're trying to do as it's defined as `ipfs.add(data, [options])`, so your function there isn't making sense to me. Docs: https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md – Discordian Jul 10 '22 at 15:40

1 Answers1

0

The await did not work as I was adding a callback frunction also. It works fine if you don't include the callback function. ie, do it like

fileHash=await ipfs.files.add(testBuffer);