Search code examples
ipfsipfs-http-client

"Failed to fetch" error message in Infura


Steps

  1. Using "ipfs-http-client" npm library
  2. setting up auth with projectId, privateKey from infura
import { create } from 'ipfs-http-client'

const privateKey = '...'
const projectId = '...'
const auth =
  'Basic ' + Buffer.from(projectId + ':' + privateKey).toString('base64')
const INFURA_URL = 'something.infura-ipfs.io'

const client = create({
  host: INFURA_URL,
  port: 5001,
  protocol: 'https',
  headers: {
    authorization: auth,
  },
  apiPath: '/ipfs/api/v0',
})

Calling ipfs client

const fileUrl = await client.add(image)

returns an error "Failed to fetch"


Solution

  • You can only use dedicated gateways to access IPFS content, not to upload content. Please follow this link for more info.

    Your solution will be to replace the sub-domain with which is something.infura-ipfs.io to ipfs.infura.io and hopefully it should work.

    For details about Dedicated gateways, please follow this link.

    Cheers.