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) => {
    const url = makeGatewayURL(cid, 'metadata.json')
    const res = await fetch(url)
    if (!res.ok) {
      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) {

Unfortunately, this is giving me a CORS error.

Is there a better way to do this?


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.