Skip to content

AKASHAorg/meteor-ipfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package:

  • Exports a global class named IpfsConnector available only on server
  • Downloads ipfs binaries
  • Can start ipfs process
  • Can send commands to ipfs api server

Example

  • On server side create a global variable just before Meteor.startup:

     // for global access on server side
     ipfsObj = false;
    
     const testIpfs = function () {
       // start ipfs daemon
       let started = ipfsObj.start();
       // wait for process to start
       if (started) {
         // test api calls https://www.npmjs.com/package/ipfs-api
         ipfsObj.api.add(new Buffer('random stuff'), (err, data)=> {
           console.log('ipfs hash ' + data[0].Hash);
         });
       }
     };
    
     Meteor.startup(function () {
       ipfsObj          =  IpfsConnector.getInstance(); //singleton
       ipfsObj.setLogLevel('info'); // info is default
       testIpfs();
     });
  • Available IpfsConnector methods:

start(); // start ipfs daemon
stop();
setLogLevel('*'); // one of ['trace', 'fine', 'debug', 'info', 'warn', 'error']
api.*; // access ipfs-api https://www.npmjs.com/package/ipfs-api
  • Server methods for client
Meteor.call('ipfsCat', ipfsHash, function(err,resp){ ... // get contents from ipfs hash

Meteor.call('ipfsAdd', string or Uint8Array, function(err,resp){ ... // upload contents to ipfs
  • FileReader example
    let reader = new FileReader();
    reader.onload = function(){
      let arrayBuffer = new Uint8Array(reader.result);

      Meteor.call("ipfsAdd", arrayBuffer, function(err, result){console.log("ipfs hash ",result);});
    };
    reader.readAsArrayBuffer('inputFileField'[0]);
  • Test this package:
VELOCITY_TEST_PACKAGES=1 meteor test-packages --driver-package velocity:html-reporter akasha:meteor-ipfs

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published