I have started to make a project now I want to use ipfs-http-client. I made a project on infura and got my project id and project secret key.

added into my js file like:

I imported using

import { create as ipfsHttpClient } from "ipfs-http-client";

import { Buffer } from 'buffer';
const projectId = '2IuYl6XXXXXXXXGJYU9UYxrrXtsr';
const projectSecret = '243164c76b145XXXXXXXXXX669b71940b37';
const auth =
'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64');

const client = ipfsHttpClient({
  host: 'ipfs.infura.io',
  port: 5001,
  protocol: 'https',
  apiPath: '/api/v0',
  headers: {
    authorization: auth,
  },
});

uploaded the file using code

const uploadToIPFS = async (file) => {
    try {
      const added = await client.add({ content: file });

      const url = `https://ipfs.infura.io/ipfs/${added.path}`;

      //setImage(url);
      return url;
    } catch (error) {
      console.log("Error uploading file to IPFS");
    }
  };

It still shows 403 forbidden whenever I try to post something onto it.

I have tried everything from reading docs to watching YouTube tutorials.

1

There are 1 answers

0
Yilmaz On

You specified your host as ipfs.infura.io, the correct address is ipfs-infura.io (- instead of .).

Change this line:

host: 'ipfs.infura.io',

To this:

host: 'ipfs-infura.io',