My app has a simple method to retrieve content with CID passed in (node 12.16.0 on windows10). Here is the method:
retrieveFromIpfs: async function(cid) {
const ipfs_node = await IPFS.create();
try {
const fileBuffer = await ipfs_node.cat(cid)
return fileBuffer;
} catch(err) {
console.log("Error retrieving file from IPFS : ", err);
return '';
}
}
The app saved a string of ātest ipfs savingā to ipfs and retrieve it back with the CID:
//retrieve
router.post(ā/retrieveā, [], async (req, res) => {
try {
const data = await helper.retrieveFromIpfs(req.cid)
console.log("ipfs data retrieved : ", data.toString());
return data;
} catch (err) {
console.log("error in retrieving ipfs file ", err);
return res.status(400).send(err.message);
}
} )
First time it returns Object [AsyncGenerator] {}
. If try 2nd time, then there is file locked error.
Here is the error on the node console:
Listening on port 3000ā¦
Executing (default): SELECT 1+1 AS result
DB connection has been established successfully.
Swarm listening on /ip4/192.168.1.6/tcp/4002/p2p/QmVxfGtbh95P1yiNVL9TmEm1tZm7SjcFbLo6UbG6SEfHJc
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/QmVxfGtbh95P1yiNVL9TmEm1tZm7SjcFbLo6UbG6SEfHJc
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/QmVxfGtbh95P1yiNVL9TmEm1tZm7SjcFbLo6UbG6SEfHJc
ipfs data retrieved : Object [AsyncGenerator] {}
error in retrieving ipfs file Error: Lock file is already being held
at C:\d\code\js\emps_bbone\node_modules\proper-lockfile\lib\lockfile.js:68:47
at callback (C:\d\code\js\emps_bbone\node_modules\graceful-fs\polyfills.js:295:20)
at FSReqCallback.oncomplete (fs.js:167:5) {
code: āELOCKEDā,
file: āC:\Users\JunC\.jsipfsā
}
Here is the example code followed on github: https://github.com/indreklasn/ipfs-node-example/blob/master/index.js