2021年3月23日星期二

Express provides me with an empty array. Push is called in an ipfs function. Log works fine

router.post('/up', verify, async (req, res) => {  if (req.files.upload.length > 0) {      var result = [];            req.files.upload.forEach((uploadFile) => {          ipfs.add(Buffer.from(uploadFile.data), function (err, upfile) {              if (err) {                  console.log(err)              } else {                  // THIS WORK                  console.log({ "name": uploadFile.name, "cid": upfile[0].path });                    // THIS NOT                  result.push({ "name": uploadFile.name, "cid": upfile[0].path });              }          })      });        res.send(result);  }});  

I get an empty result. How can I fix it? And what is the reason? I don't really understand it ...

https://stackoverflow.com/questions/66773240/express-provides-me-with-an-empty-array-push-is-called-in-an-ipfs-function-log March 24, 2021 at 08:46AM

没有评论:

发表评论