How to add files using ipfs-http-client

Hello :wave: all

If you’d like to test the ipfs-http-client Javascript library for adding a File, please follow the steps below.

Use the official ipfs-http-client for installing the library.

Prerequisites: Use your own Project ID and Project Secret.

Please note that you have to create a folder structure with your files in it. In my example my folder structure looks like: docs/hello.txt

const {ipfsClient, globSource, create} = require('ipfs-http-client')

const projectId = '23...XXX';
const projectSecret = '23...XXX';
async function addFile(){
	const auth =
	  'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64')

    const client = await create({
        host: 'ipfs.infura.io',
        port: 5001,
        protocol: 'https',
        headers: {
          authorization: auth
        }
      })
 
      for await (const file of client.addAll(globSource("./docs", "**/*"))) {
        console.log(file)
      }
}

addFile()
1 Like