Access ipld block through gateway

Hello ipfs-newbie here, I have a question in regards to accessing/distributing the cid of ipld blocks created with:

import Block from "@ipld/block/defaults";

const block = Block.encoder(obj, "dag-cbor");
const data = block.encode();
const cid = await block.cid();

// js-ipfs uses an older CID value type so we must convert to string
await ipfs.block.put(data, { cid: cid.toString() });

how can i resolve the bafy hash cid through a gateway (similar to this question) / how can i use dnslink to map a human readable url to the cid?

Technically you can access using the Read API. ie:

(also block/get).

I don’t think you can DNS-link this as the gateway endpoint itself seems to only like dag-pb/unixfs DAGs.

There is work related to make dag-cbor accessible: feat: serve CBOR encoded DAG nodes from the gateway by alanshaw · Pull Request #8037 · ipfs/go-ipfs · GitHub

1 Like

Hey @hector, thank you for your answers. Glad this is being worked on.

One more question tho. Let’s say i encode my data as dag-pb can i then use pathing through the gateway like<cid><uri-encoded-path>?

No, you will have to wait to the feature above for pathing on arbitrary ipld objects to work I think.

Okay i will try it out later just to make sure