IPFS-http-client depricated

Hi, It looks like last week June 13 2023, ipfs-http-client was deprecated. This is bad because it is how I am connecting to my IPFS dedicated gateway as per this issue: Add file to ipfs (node.js) - #4 by Flaveeu

Here is my code:

const fs = require('fs');
const dotenv = require('dotenv');
dotenv.config();

//infura config
const ipfsClient = require('ipfs-http-client');
const projectId = process.env.API_KEY;
const projectSecret = process.env.API_SECRET;
const logger =require('./logger');
const axios = require('axios');


const auth = 'Basic ' + Buffer.from(projectId+':'+projectSecret).toString('base64');
const client = ipfsClient.create({
    host: 'ipfs.infura.io',
    port: 5001,
    path: '/api/v0/add',
    protocol: 'https',
    headers: { authorization: auth,},
});


async function ipfsUploadFunction(folder, index, public_id){
    const logs =logger.newLogger({fileName:'ipfsUpload.js',function:'ipfsUploadFunction', id:public_id});
    logs.info("\n***** Configuring IPFS... *****");
    try{
        file = fs.readFileSync(folder + index); 
        let cid = await client.add(file);
        console.log(`*** successful transaction: ${cid.cid.toString()} ***`);
        return cid.cid.toString();
    }catch(err){
        logs.error("what is this error? " +err);
        return ('failed');
    }
};

The error I am getting is this:

TypeError: RequestInit: duplex option is required when sending a body.

If anyone has a fix for me please let me know!

@dvncan

2 Likes

hey, it might be just a Node issue see RequestInit: duplex option is required when sending a body · Issue #46221 · nodejs/node · GitHub
What node version are you using ?

As for Helia, it looks like it doesn’t support yet connecting to a remote ipfs provider but we’ll keep an eye and add tutorials when the time comes.

1 Like

Hey, node version is 18.12.1 and I think it is more likely because the library has been closed and made read only (on june 13 2023). Can you please verify that your solution still works as described by

1 Like

I found a solution which works for postman which is to use the IPFS endpoint I will outline how I configured it below.

Remove all origin restrictions… I have not had any success setting ip restrictions and it creates confusion, I wrote about it here.

Set postman Auth to Basic Auth & API_KEY:API_SECRET

POST : https://ipfs.infura.io:5001/api/v0/add

Include the file path in the request body, I used form-data and selected the down arrow in the key section to toggle the request to file.
External Image

1 Like

Hey this is still an issue for me. I was getting axios object error which is described here when trying to do the call programmatically.

1 Like

@traian.vila I didn’t tag you in my reply but I added some context to the ticket.

1 Like

do you have any allowed origins set in your ipfs key security settings ?

1 Like

@traian.vila
I removed all restrictions so the key is open. it works with postman but i am getting an axios error doing it programmatically

see below:

async function ipfsPostFunction(folder, index, public_id){
    const logs =logger.newLogger({fileName:'ipfsUpload.js',function:'ipfsUploadFunction', id:public_id});
    logs.info("\n***** Configuring IPFS... *****");
    try{        
        let API_KEY = process.env.API_KEY;
        let API_SECRET = process.env.API_SECRET;
        const projectIdAndSecret = `${API_KEY}:${API_SECRET}`
        const auth = `Basic ${Buffer.from(projectIdAndSecret).toString('base64')}`
        let url = 'https://ipfs.infura.io:5001/api/v0/add';
        let file = `file=@".${folder}/${index}}"`



        let options = {headers: {authorization: auth,'Content-Type': "multipart/form-data"},};
        console.log(options);

        let response = await axios.post(url, file, options );

        response.on('response', function (response) {

            response = JSON.parse("[" + data.split("}\n{").join("},{") + "]");
                  return data;
                
              
        });
        // console.log(response);

    
        // console.log(`*** adding file: ${file}... ***`);
        // let cid = await client.add(file);
        // console.log(`*** successful transaction: ${cid.cid.toString()} ***`);
        // figure out how to skip if already contained in list.
        // return cid.cid.toString();
    }catch(err){
        logs.error("IPFS Failure: " +err);
        return ('failed');
        // cidList.push(err);
    }
    //console.log(cidList)
}

someone wrote to transform the response but I couldn’t find the exact way to do that… The error is an open bug for objects which are not proper JSON.

1 Like

@dvncan @traian.vila I am seeing the same issue as of last week. I tried the helia route, but encountered the same problem of not being able to configure Infura as a 3rd party node. Still researching possible alternatives, but hitting a dead end for now and this is a blocker for some production work that needs to be done unfortunately.

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.