The IpfsAPI allows you to interact with IPFS through Fileroom.
Import the IpfsAPI from the client:
const { ipfs } = client;
Check the pinning status of a CID.
const status = await ipfs.status('Qmabc123...');
Returns:
{
"peername": "peer name",
"status": "pinned",
"ipfs_peer_id": "peer id",
"ipfs_peer_addresses": [
"/ip4/127.0.0.1/tcp/4001/ipfs/QmPeerId"
],
"timestamp": "ISO date string",
"error": "",
"attempt_count": 1,
"priority_pin": true,
"metadata": {},
"created": "ISO date string"
}
Fetch a file from the gateway by CID.
const stream = await ipfs.get('Qmabc123...');
Option | Type | Description |
---|---|---|
origin | string | Gateway origin, defaults to Fileroom gateway |
size | string | Preview size string (e.g. '200x200') |
Returns: Promise<Stream>
Pin a CID to Fileroom's IPFS cluster.
await ipfs.pin('Qmabc123...');
Option | Type | Description |
---|---|---|
resize | string[] | Array of preview size strings to generate on pinning |
Returns:
{
"message": "pinned successfully",
"result": {
"docId": "doc id",
"cid": "pinned cid",
"previews": [
{
"cid": "preview cid 1",
"size": "200x200"
},
{
"cid": "preview cid 2",
"size": "400x400"
}
]
},
"listenTo": {
"wsUrl": "ws url",
"event": "pinning_progress"
}
}