How to upload multiple files from a directory using ipfs-http-client

Hello everyone,

You can use the ipfs-http-client Javascript library to add multiple files from a directory by making use of the globSource utility. In order to do so, please follow the below steps:

Install the library from the official ipfs-http-client
Add the content to your Infura IPFS project by specifying the path to your directory from where the files will be fetched together with a pattern to match the files under your path.
Don’t forget to use your Project ID and Project Secret.

const { globSource, create} = require('ipfs-http-client')
const projectId = '27xxxsj';
const projectSecret = '20xxx5b';

async function addFolder(){
  const auth =
    'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64')
    const client =  create({

        host: '',
        port: 5001,
        protocol: 'https',
        headers: {
          authorization: auth

    for await (const file of client.addAll(globSource('/home/user/path/to/directory', '**/*'))) {

1 Like