Ipfs.add() not working

Hey Updating the baseUri, syncing and uploading the metadata and file to ipfs at doesn’t run at all. I keep getting
const fetch = require(‘node-fetch’);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module C: … index.js from C:(file location)/uploadFiles.js not supported
Instead change the require of index.js in C:(file location)uploadFiles.js to a dynamic import() which is available in all CommonJS modules.
at Object. (file location) {
Code: ‘ERR_REQUIRE_ESM’}
Please how do I resolve this cus it’s a barrier

Hello everyone, I am new here. I am facing some issue with IPFS. the following code i am using for image upload to ipfs.infura.io gateway in my form. it was working fine but from few days it’s giving me this error. need your kind help!

Error: /api/v0/object has been removed, use /api/v0/dag instead

Hi :wave: @younas and welcome to the Infura community!

Could you share with us a code snippet you used for image upload?

Are you using /api/v0/object by change? Please note, that method has been deprecated and you should use /api/v0/dag instead.

hello, I got the same problem. When I run the program, it shows "https://ipfs.infura.io:5001/api/v0/add?stream-channels=true&progress=false CORS request did not succeed ". I tried to use the URL that I run successfully before, but now I can’t get in and show this message.

Is there any way to fix it to make it run successfully?

Hey @Cal please refer to the following.
https://infura.discoursehosting.net/t/ipfs-authentication-error-403-forbidden/5672/50
The change was reverted that was affecting client-agents, but you still should use Dedicated getaway as of now, as the Public getaway has been deprecated.
https://docs.infura.io/infura/networks/ipfs/how-to/access-ipfs-content/public-gateway

hey can you help me? yesterday my project was working successfully and was able to upload files and get that hash. today it gives this message in console
POST https://ipfs.infura.io:5001/api/v0/add?stream-channels=true&progress=false 401 (Unauthorized)

This is what i do in my code:-

** Setting up ipfs client: **

import { create } from 'ipfs-http-client'
const ipfs = create({ host: 'ipfs.infura.io', port: 5001, protocol: 'https', apiPath: '/api/v0' });

** Uploading my file : **

const uploadFile = description => {

    // console.log("ipfs client : ", ipfs)

    // console.log("submitting the file to IPFS with description: ", description)

    // console.log("buffer is : ", buffer);

    //Add file to the IPFS

    //from infura documentation

    ipfs.add(buffer)

      .then(

        result => {

          console.log("result is ", result)

          //Set state to loading

          setLoading(true);

          //Assign value for the file without extension

          if (type == null) {

            setType('none')

          }

          console.log("our smart contract is ", ddBox)

          console.log("our method is ",ddBox.functions.uploadFile)

         

        const callMethod=async ()=>{

          try {

           

           const tx= await ddBox.functions.uploadFile(result.size, result.path, type, name, description);

           console.log("transaction is : ",tx)

           console.log(tx.hash)

           setLoading(false);

            setType(null);

            setName(null);

            window.location.reload()

          } catch (error) {

            window.alert('Error')

            setLoading(false)

          }

        }

        callMethod();

        }

        )

      .catch(error => console.error(error))

  }

@lovekosmas It worked! Thank you!

1 Like

@lovekosmas @mike can someone please help. i am trying from 3 days to resolve this

@Abhinav_Agarwal, what is in your “buffer”?
Can you make sure you are including Authentication when uploading files?

Please check out this example:
https://infura.discoursehosting.net/t/how-to-add-files-using-ipfs-http-client/5180

I am also getting the same issue anyone please help … Facing since 3 weeks (same issue) … :frowning_face:

The issue :
fetch.browser.js?c17b:107 POST https://ipfs.infura.io:5001/api/v0/add?stream-channels=true&progress=false 401 (Unauthorized)

The github link for the file :

https://github.com/Vikash-8090-Yadav/Sal-DApp/blob/main/Sal-DAp/Component/Form/component/Addemp.js

@mike @lovekosmas someone please help…Getting this error since 3 weeks. :disappointed:

Hi @Vikash_Kumar_yadav You’ll need to pass authentication to your IpfsApi, here’s an example How to add data using ipfs-http-client

@Flaveeu while i am making project in the ipfs at that time it is asking for my card details . Is this true ?

It’s showing this error after adding the auth like the above mentioned in the link ,

I am also getting the same issue anyone

Hi muma, welcome! Have you reviewed this answer yet:

If so, please provide your code and error message?

Hello,
We are currently working on our Final Year Project-Dropbox clone using blockchain and ipfs.
We are facing an issue where we upload the file and without showing the hash value it is saying that the result is undefined.
Hoping for your response soon.
Thank You.

Code:
import DStorage from ‘…/abis/DStorage.json’

import React, { Component } from ‘react’;

import Navbar from ‘./Navbar’

import Main from ‘./Main’

import Web3 from ‘web3’;

import ‘./App.css’;

//Declare IPFS

import create from “ipfs-http-client”

async function ipfsClient() {

const ipfs = await create(

  {

      host: "https://dropstore.infura-ipfs.io",

      port: 5001,

      protocol: "https"

  }

);

return ipfs;

}

const projectId = ‘2JX2tj4qGIN0cBMOnUZxOWX2GrT’;

const projectSecret = ‘b15e378d90583ae9d86edd8117f17326’;

const auth = ‘Basic’ + Buffer.from(projectId + “:” + projectSecret).toString(‘base64’);

class App extends Component {

async componentWillMount() { //lifecycle callback in react->when component gets added to dom/page,this function is going to run

await this.loadWeb3()       //connects the app to the blockchain

await this.loadBlockchainData() //connects the web3 console

}

async loadWeb3() { //this code function connects the app to the blockchain

//Setting up Web3

if (window.ethereum){

  window.web3 = new Web3(window.ethereum)

  await window.ethereum.enable()

}

else if(window.web3){

  window.web3 = new Web3(window.web3.currentProvider)

}

else {

  window.alert('Non-Ethereum browser detected.You should consider trying MetaMask!')

}

}

async loadBlockchainData() {

const web3 = window.web3//Declare Web3

console.log(web3)

//Load account

const accounts = await web3.eth.getAccounts()

this.setState({ account:accounts[0] })

//Network ID

const networkId = await web3.eth.net.getId()

const networkData = DStorage.networks[networkId]

if(networkData){

  //Assign contract

  const dstorage = new web3.eth.Contract(DStorage.abi, networkData.address)

  this.setState({dstorage})

  //Get files amount

  const filesCount = await dstorage.methods.fileCount().call()

  this.setState({filesCount})

  //Load files&sort by the newest

  for (var i = filesCount; i>= 1; i--){

    const file = await dstorage.methods.files(i).call()

    this.setState({

      files: [this.state.files, file]

    })

    console.log(this.state.files)

  }

}else {

  window.alert('DStorage contract not deployed to detected network.')

}

this.setState({loading: false})

//Else

  //alert Error

    this.setState({loading: false})

}

// Get file from user

captureFile = event => {

event.preventDefault()

const file = event.target.files[0]

const reader = new window.FileReader()

console.log(file)

reader.readAsArrayBuffer(file)

reader.onloadend = () => {

  this.setState({

    buffer: Buffer(reader.result),

    type: file.type,

    name: file.name

  })

  console.log('buffer', this.state.buffer)

}

this.setState({

  type: file.type,

  name: file.name

})

}

//Upload File

uploadFile = async () => {

console.log("Submitting file to ipfs...")

let ipfs = await ipfsClient();

console.log(this.state);

const result = await ipfs.add(this.state.name, (result, error) => {

  console.log('ipfs result',result);

  console.log("ipfs result", error);

})

}

constructor(props) {

super(props)

this.state = {

  buffer:[],

  account: '',

  dstorage: null,

  files: [],

  loading: false,

  type: null,

  name: null

}

this.uploadFile = this.uploadFile.bind(this)

this.captureFile = this.captureFile.bind(this)

}

//Bind functions

//React->javascript library to build user interface.

render() {

return (

  <div>

    <Navbar account={this.state.account} />

    { this.state.loading

      ? <div id="loader" className="text-center mt-5"><p>Loading...</p></div>

      : <Main

          files={this.state.files}

          captureFile={this.captureFile}

          uploadFile={this.uploadFile}

        />

    }

  </div>

);

}

}

export default App;

Output:

Hello,
We are currently working on our Final Year Project-Dropbox clone using blockchain and ipfs.
We are facing an issue where we upload the file and without showing the hash value it is saying that the result is undefined.
Hoping for your response soon.
Thank You.