0

I'm trying to display files stored on IPFS via web3.storage like this in my front end application:

const makeGatewayURL = (cid, path) => {
  return `https://${cid}.ipfs.dweb.link/${encodeURIComponent(path)}`
}
const getImageMetadata = async (cid) => {
  try{
    const url = makeGatewayURL(cid, 'metadata.json')
    const res = await fetch(url)
    if (!res.ok) {
      console.log(res)
      throw new Error(`error fetching image metadata: [${res.status}] ${res.statusText}`)
    }
    const metadata = await res.json()
    const gatewayURL = makeGatewayURL(cid, metadata.path)
    const uri = `ipfs://${cid}/${metadata.path}`
    return { ...metadata, cid, gatewayURL, uri }
  }
  catch (e) {
    console.log(e)
  }
}

Unfortunately, this is giving me a CORS error.

Is there a better way to do this?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.