ipfs.dag.get error #3854
Description
Regarding the BUG in ipfs.dag.get, the sample code in the ipfs.dag.get part of https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/DAG.md cannot be run normally.
The following code can run normally and get the hash value: bafyreicyer3d34cutdzlsbe2nqu5ye62mesuhwkcnl2ypdwpccrsecfmjq
const { create } = require('ipfs-http-client')
const CID = require('cids');
const ipfs = create({ host: '127.0.0.1', port: '5001', protocol: 'http' })
var cid = async function(obj) {
return await ipfs.dag.put(obj, { format: 'dag-cbor', hashAlg: 'sha2-256' });
}
const obj = {
a: 1,
b: [1, 2, 3],
c: {
ca: [5, 6, 7],
cb: 'foo'
}
}
cid(obj).then((ret) => {
console.log(ret.toString())
});
Then use the hash value obtained and use the code in the example to get the data, and an error will be reported: No codec found for "undefined".code show as below:
const { create } = require('ipfs-http-client')
const CID = require('cids');
const ipfs = create({ host: '127.0.0.1', port: '5001', protocol: 'http' })
async function getAndLog(cid, path) {
const result = await ipfs.dag.get(cid, { path:path })
}
getAndLog('bafyreicyer3d34cutdzlsbe2nqu5ye62mesuhwkcnl2ypdwpccrsecfmjq', '/a').then((ret) => {
console.log(ret)
});
I tried several times and found that it was a cid problem. After modifying the code, I tried to run again, no more errors were reported, but the output value is always: undefined.code show as below:
const { create } = require('ipfs-http-client')
const CID = require('cids');
const ipfs = create({ host: '127.0.0.1', port: '5001', protocol: 'http' })
async function getAndLog(cid, path) {
const result = await ipfs.dag.get(new CID(cid), { path:path })
}
getAndLog('bafyreicyer3d34cutdzlsbe2nqu5ye62mesuhwkcnl2ypdwpccrsecfmjq', 'a').then((ret) => {
console.log(ret)
});
Use the cli command directly to obtain the data, and the data can be obtained normally.
Why is this so?