POST https://ipfs.infura.io:5001/ipfs/api/v0/add?stream-channels=true&progress=false 403 (Forbidden). HTTPError: ipfs method not supported

Below is how i create the client.

import { create as ipfsHttpClient } from 'ipfs-http-client';
const projectId = 'xx';
const projectSecret = 'xx';
const auth = `Basic ${Buffer.from(`${projectId}:${projectSecret}`).toString('base64')}`;
const options = {
  host: 'ipfs.infura.io',
  protocol: 'https',
  port: 5001,
  apiPath: '/ipfs/api/v0',
  headers: {
    authorization: auth,
  },
};
const dedicatedEndPoint = 'https://xx.infura-ipfs.io';
const client = ipfsHttpClient(options);

Here is the function that will be called from front-end that takes in a file, uploads to IPFS and returns URL. Please note that the “ipfsHTTPClient()” is just the create function.

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

      const url = `${dedicatedEndPoint}${added.path}`;

      return url;
    } catch (error) {
      console.log('Error uploading file to IPFS: ', error);
    }
  };

The error I am getting is

POST https://ipfs.infura.io:5001/ipfs/api/v0/add?stream-channels=true&progress=false 403 (Forbidden) 

When i console log the error it says the IPFS method is not supported.

On the IPFS forum, i have seen someone say that add function does not work anymore but i have also seen people using it and it working. Im not sure whats wrong here.

Here is how i call the function on front-end

const { uploadToIPFS } = useContext(NFTContext);

// function called from useDropzone
const onDrop = useCallback(async (acceptedFile) => {

    const url = await uploadToIPFS(acceptedFile[0]);

    setFileUrl(url);
}, []);

Hey, I’m pretty sure that this path should only be '/api/v0'

I have done everything from reading docs to watching numerous videos. it still does not work. same error 403 forbidden. Please help infura team.

Hi @akarsh_srivastav,

post your code and let’s see if we can help.

Warm regards,
Chris | Infura | ConsenSys

Hi @akarsh_srivastav,

you haven’t shown all the code on SO, so I’m not sure what’s wrong. If your API key or secret were not correct, then I’d expect a 401 error, I’m not sure where the 403 is coming from.

I don’t think the answers on SO are correct - https://ipfs.infura.io:5001 is correct for accessing the API. Note however, that where you access the gateway:

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

is not correct. We removed the public gateway on infura some time ago and now you must define a dedicated gateway in your project and use that instead. Searching our docs for dedicated will show you how. But, that’s not why you are getting the 403 - unless it the commented out “setImage” that’s causing that?

If you can point us to a github repo with all your code we can be more definitive.

Chris