IPFS-Depricated-NOFIX

This is a continuation of the ticket: IPFS-http-client depricated

@traian.vila Can you please take a look into this? I was only using Infura as an IPFS gateway it is a huge blocker that it is no longer supported.

Also a quick fix may be to fix the object returned from a post request so that Axios works with that route.

1 Like

Hey, sorry, I haven’t got the chance to craft a working axios example but we’ve recently added the kubo-rpc one which pretty much replaces the ipfs-http-client (with minimal changes) Make requests | INFURA

Let me know if that helps.

1 Like

Thanks for the suggestion, do you have any examples for adding new files?

Here is what I have for config:

        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}}"`

Next in the function is the axios call but at the top of the link you had just posted there is a nodejs pin request, does that format work for posting files?

1 Like

Uploading a file would look like this:

import { create } from 'kubo-rpc-client'
import fs from 'fs'

const projectId = '...'
const projectSecret = '...'


async function main() {

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

    var file = fs.readFileSync("./image.png");

    try {
    const ipfs = await client.add(file);
    console.log(ipfs);

    console.log('https://ipfs.io/ipfs/' + ipfs.path)

    } catch (error) {
      console.log(error)
    }

}
main();
1 Like

@dvncan I was able to fix using the following:

import { IPFS } from "ipfs-infura";

        const ipfs = new IPFS({
          host: process.env.IPFS_PUBLIC_URL || "ipfs.infura.io",
          port: 5001,
          protocol: "https",
          projectId: process.env.IPFS_INFURA_PROJECTID,
          projectSecret: process.env.IPFS_INFURA_SECRET,
        })

        const cid = await ipfs.add(JSON.stringify(meta));
1 Like

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