Skip to content

Commit e6e6ebb

Browse files
authored
Example for using DAG-PB for storing multiple chunks (#85)
* Example for using DAG-PB for storing multiple chunks (TODO: needs polish) * Fixed DAG file type? * Some progress with DAG stuff (almost working) * Stored chunked file and retrieve * Removed * DAG example * Final version * Store verify proof for DAG rootCID
1 parent c95e6ad commit e6e6ebb

File tree

3 files changed

+405
-17
lines changed

3 files changed

+405
-17
lines changed

examples/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ docker pull ipfs/kubo:latest
5757
docker run -d --name ipfs-node -v ipfs-data:/data/ipfs -p 4001:4001 -p 8080:8080 -p 5001:5001 ipfs/kubo:latest
5858
docker logs -f ipfs-node
5959
# Connect nodes
60-
docker exec -it ipfs-node ipfs swarm connect /ip4/172.17.0.1/tcp/10001/ws/p2p/12D3KooWQCkBm1BYtkHpocxCwMgR8yjitEeHGx8spzcDLGt2gkBm
61-
docker exec -it ipfs-node ipfs swarm connect /ip4/172.17.0.1/tcp/12347/ws/p2p/12D3KooWRkZhiRhsqmrQ28rt73K7V3aCBpqKrLGSXmZ99PTcTZby
60+
docker exec -it ipfs-node ipfs swarm connect /ip4/172.17.0.1/tcp/10001/ws/p2p/12D3KooWQCkBm1BYtkHpocxCwMgR8yjitEeHGx8spzcDLGt2gkBm && docker exec -it ipfs-node ipfs swarm connect /ip4/172.17.0.1/tcp/12347/ws/p2p/12D3KooWRkZhiRhsqmrQ28rt73K7V3aCBpqKrLGSXmZ99PTcTZby
6261
6362
# specific version
6463
# docker pull ipfs /kubo:v0.35.0
@@ -73,6 +72,24 @@ docker exec -it ipfs-node ipfs swarm connect /ip4/172.17.0.1/tcp/12347/ws/p2p/12
7372
```
7473
# cd polkadot-bulletin-chain - make sure we are here
7574
cd examples
76-
npm install @polkadot/api @polkadot/keyring @polkadot/util-crypto @polkadot/util multiformats ipfs-http-client
75+
npm install @polkadot/api @polkadot/keyring @polkadot/util-crypto @polkadot/util multiformats ipfs-http-client ipfs-unixfs
76+
```
77+
78+
### Example for simple authorizing and store
79+
```
7780
node authorize_and_store.js
7881
```
82+
83+
### Example for multipart / chunked content / big files
84+
The code stores one file, splits into chunks and then uploads those chunks to the Bulletin.
85+
It collects all the partial CIDs for each chunk and saves them as a custom metadata JSON file in the Bulletin.
86+
87+
Now we have two examples:
88+
1. **Manual reconstruction** — return the metadata and chunk CIDs, then reconstruct the original file manually.
89+
2. **IPFS DAG feature**
90+
* converts the metadata into a DAG-PB descriptor,
91+
* stores it directly in IPFS,
92+
* and allows fetching the entire file using a single root CID from an IPFS HTTP gateway (for example: `http://localhost:8080/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ`).
93+
```
94+
node store_chunked_data.js
95+
```

examples/authorize_and_store.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,12 @@ async function store(api, pair, data) {
3636
return cid
3737
}
3838

39-
// Connect to a local IPFS node or Infura/IPFS gateway
39+
// Connect to a local IPFS gateway (e.g. Kubo)
4040
const ipfs = create({
4141
url: 'http://127.0.0.1:5001', // Local IPFS API
4242
});
4343

44-
// async function test() {
45-
// try {
46-
// const id = await ipfs.id();
47-
// console.log('✅ Connected to IPFS node:');
48-
// console.log('Peer ID:', id.id);
49-
// console.log('Addresses:', id.addresses);
50-
// } catch (err) {
51-
// console.error('❌ Failed to connect to IPFS:', err.message);
52-
// }
53-
// }
54-
5544
async function read_from_ipfs(cid) {
56-
// await test();
57-
5845
// Fetch the block (downloads via Bitswap if not local)
5946
console.log('Trying to get cid: ', cid);
6047
const block = await ipfs.block.get(cid);

0 commit comments

Comments
 (0)