I'm using js-ipfs server side to 'upload' files on IPFS, but it seems like it's way less efficient than the command line ipfs daemon
and ipfs add someFile
.
Server-side, I instanciate an Ipfs
object and then I try to storeData
with a path and the buffer of the content of the file. I am connected to three swarms when my server starts:
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/ipfs/QmTBoDWXviw7eRKeDGbp3wU2PxAw1epPxax6mp8uY6CEEW
Swarm listening on /ip4/127.0.0.1/tcp/4002/ipfs/QmTBoDWXviw7eRKeDGbp3wU2PxAw1epPxax6mp8uY6CEEW
Swarm listening on /ip4/10.19.77.89/tcp/4002/ipfs/QmTBoDWXviw7eRKeDGbp3wU2PxAw1epPxax6mp8uY6CEEW
I use IPFS this way :
const IPFS = require('ipfs');
const node = new IPFS();
class Ipfs {
constructor() {
node.on('error', e => console.log(e))
node.on('start', () => console.log('Node started !'))
node.on('ready', () => console.log('Node is ready !'))
}
storeData(content, path) {
return new Promise((resolve, fail) => {
let encData = {
path: path,
content: content,
};
node.files.add(encData, (err, data) => {
if (err) return fail(err);
return resolve(data);
})
})
}
}
When I call storeData
from my object, IPFS gives me a hash back where I can get my file, but the https://ipfs.io/ipfs/[hash]
never loads.
I want to insist on the fact that the hash given by the ipfs add
command line works instantly
Thanks in advance