Ishwar
Ishwar

Reputation: 6171

ipfs.add() returns Object [AsyncGenerator] {}

I am unable to figure out what mistake i have done in the code

Whenever i am calling api, ipfs.add('hello') returns [object AsyncGenerator]

https://gateway.ipfs.io/ipfs/[object AsyncGenerator]

  const addFile = async () => {
            const Added = await ipfs.add('hello');
            return Added;
        }
        const fileHash = await addFile();
        return fileHash;

Upvotes: 0

Views: 1629

Answers (1)

Dietrich Ayala
Dietrich Ayala

Reputation: 941

You can iterate over the result of .add() like so:

for await (const item of Added) {
  console.log('item', item)
} 

item { path: 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX',
cid: CID(QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX), size: 13 }

Upvotes: 3

Related Questions