Ipfs.add() is not returning any hash

I started to learn IFPS and below is the code I typed in my terminal to connect to the IPFS network

    > const ipfsClient = require('ipfs-http-client')
    > const ipfs = ipfsClient('https;//ipfs.infura.io:5001')
    > ipfs.add("data",(err,res)=>{console.log("ipfs: ",res)})

I was expecting any hash or error as output but terminal returned
Object [AsyncGenerator] {}

Previously I have tried to implement IPFS through javascript,

onSubmit = (event)=>{
event.preventDefault()
console.log("Submitting...")
console.log(this.state)
ipfs.add(this.state.buffer,(error,result)=>{
  console.log("Working")
  console.log("IPFS Result",result)
  // if(error) {
  //   console.error(error)
  //   return
  // }
})
  }

But on calling onSubmit, no output was shown except the string “Submitting” and the value of the state variable buffer.

It would be very kind if someone help me out with what the problem is.

Hi @neucleophile it appears as though your URL may be incomplete, the add() method is documented here, https://infura.io/docs/ipfs/post/add

Try updating your URL per the format in the docs link and let me know if that helps!

Hi mike,

I am facing similar issue getting below error
UnhandledPromiseRejectionWarning: HTTPError: ipfs method not supported

below is the code

const auth =

'Basic ’ + Buffer.from(projectId + ‘:’ + projectSecret).toString(‘base64’)

const ipfs = ipfsClient.create ({

host: 'ipfs.infura.io',

port: 5001,

protocol: 'https',



headers: {

    authorization: auth

  },

  apiPath: '/ipfs/api/v0'

})

try{

    return new Promise((resolve, reject) => {

        ipfs.add(buffer, async (err, res,next) => {

            console.log(res);

            if (err) {

                console.error(err);

            } else {

                const hash = await res[0].hash;

                console.log(hash)

                resolve(hash);

            }

        })

    })

}

catch(error){

    next(error)

    console.log(error)

}

any help really appreciated , i really stuck here to proceed further with development.

Hey @komaturir,

We recently updated our IPFS offering and have a new syntax for adding files - you can check it out here!