How to host files using InterPlanetary File System IPFS

InterPlanetary File System in short IPFS is a new hypermedia distribution protocol, addressed by content and identities. IPFS enables the creation of completely distributed applications. Besides, it is also a distributed file system that seeks to connect all computing devices with the same system of files. IPFS is more similar to the BitTorrent to host files peer to peer without the intermediary involved. The point of creating IPFS is to solve HTTP problems such as DDOS and server issues. Day by day, IPFS is becoming a new major subsystem of the internet and it could complement or replace HTTP. In this tutorial, I will teach you on how to host files using interplanetary file system IPFS on your computer.

Install IPFS

You need to install IPFS on your computer. Visit ipfs.io/docs/install/ to get it right now.

Init the IPFS

To init the IPFS, open your terminal or command prompt and insert the following command line.

ipfs init

You will see this output in your terminal

initializing ipfs node at /Users/jbenet/.go-ipfs
generating 2048-bit RSA keypair...done
peer identity: Qmcpo2iLBikrdf1d6QU6vXuNb6P7hwrbNPW9kLAH8eG67z
to get started, enter:

  ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme

Start IPFS

Enter “ipfs daemon” in your terminal to start the ipfs services on your computer.

ipfs daemon

Check IPFS peers

After starting the ipfs services, you can check connected peers by the following command line.

ipfs swarm peers

Open IPFS Object

To get the objects from the IPFS network and download it on your computer.

ipfs cat /ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg >cat.jpg 
open cat.jpg

Check Local IPFS Object

It will display a list of hash that your local ipfs downloaded the object.

ipfs refs local

Add File to IPFS Network

To add files to the IPFS network, you can type the following command in your terminal. Example u want to upload “abc.png”.

ipfs add -r abc.png

To make it online forever

By pinning the object, it disables garbage collection within 24 hours, the file will available as long as your daemon is running. That’s mean if you didn’t pin it, the files will disappear in the network within 24 hours.

ipfs pin add -r abc.png

To access the file

Go to the gateway.ipfs.ios ipfs link

//gateway.ipfs.io/ipfs/<hash>

or your localhost ipfs link

//localhost:8080/ipfs/<hash>

Web Console

You can check nodes and your peers in the web console by just access it.

//localhost:5001/webui

Example screenshot of Web console

(Visited 950 times, 1 visits today)
Advertisements

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *