Error when I try to add ipfs file with my nodejs Dapp

124 Views Asked by At

I am trying to create a Dapp with nodejs that allow me to upload a file to IPFS running in local, but I'm haveing some troubles.

I've tried the next

submit_change: document.getElementById('upload_form').addEventListener('submit', async function(event) {
    
    event.preventDefault();


    const ipfs = create({host: "127.0.0.1", port: 8081, protocol: "http"})


    await ipfs.add("Hello world!", (error, res) => {
      console.log(res)
      if(error){
        console.log(err)
      }
    })

  }),

But I get this:

POST http://127.0.0.1:8081/api/v0/add?stream-channels=true&progress=false 404 (Not Found)
fetch @ http.js:147
Client.fetch @ core.js:148
post @ http.js:189
addAll @ add-all.js:23
await in addAll (async)
last @ index.js:13
add @ add.js:25
eval @ index.js:98
core.js:67 Uncaught (in promise) HTTPError: 404 page not found

    at Object.errorHandler [as handleError] (core.js:67:15)
    at async Client.fetch (http.js:155:9)
    at async addAll (add-all.js:23:17)
    at async last (index.js:13:20)
    at async HTMLFormElement.eval (index.js:98:5)
errorHandler @ core.js:67

In theory, IPFS is running in the port 8081 and the app in the 8080. If I add something from my linux terminal with the comand "ipfs add", it works fine and I can se what I've uploaded with the url http://127.0.0.1:8081/ipfs/hash.

What am I doing wrong in my Dapp

1

There are 1 best solutions below

0
On

You can check out Moralis IPFS API which makes this process a lot easier! Here you can find a guide on how to use it https://docs.moralis.io/web3-data-api/evm/how-to-upload-a-folder-to-ipfs.

Let me know if you need any help!

Disclosure: I work at Moralis