Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

ipfs.dag.get error #3854

Closed
Closed
@longren610

Description

@longren610

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())
});

image

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)
});

image

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)
});

image

Use the cli command directly to obtain the data, and the data can be obtained normally.
image

Why is this so?

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions