Steps
- Using "ipfs-http-client" npm library
- 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"