Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
How do I differentiate b/w a ipfs url/path (content-addressed) from normal-url (location-addressed)?

I am trying to fetch nft-metadata for the nfts added on my platform. Some Nfts contains ipfs-urls as their tokenURIs and I need a mechanism to differentiate them from normal-urls (location-addressed urls).

I was using is-ipfs, but it gives false returns even for valid ipfs-urls!

if (mtokenUri) {
  var res;
  var data;

  console.log("### ipfs url check ###");
  console.log(
    isIPFS.urlOrPath(
      "ipfs://bafybeihbsysdkemc3kyylegtfopkrcfiih4exnasoql2q36fb4zawlrwhy/volcano.json",
    ),
  );
  // false for "ipfs://bafybeihbsysdkemc3kyylegtfopkrcfiih4exnasoql2q36fb4zawlrwhy/volcano.json"

  //this is not very reliable
  if (isIPFS.urlOrPath(mtokenUri)) {
    //gives false even for a valid ipfs-url
    console.log("inside erc721 ipfs: ");

    isIpfsUrl = true;
    console.log("*** 721 isIpfs url ***");
    console.log(isIPFS.urlOrPath(mtokenUri));
    // example ccid = 'QmPzhc9ezphJ85qJWfVVpeHkPieDJznpYduGhMYD7Z4Ac9'
    const cid_eg2 =
      "bafybeihbsysdkemc3kyylegtfopkrcfiih4exnasoql2q36fb4zawlrwhy/volcano.json";
    try {
      res = await ipfs.cat(mtokenUri);
      // data = await res.json()
      console.log(res);
    } catch (error) {
      console.log(error);
    }

    //shows:cat {<suspended>}
  } else {
    //do normal fetch

    try {
      res = await fetch(mtokenUri);
      data = await res.json();

      console.log("erc721 normal fetch");
      console.log("*** Normal fetch data *** ");

      console.log(data);
      _imageUrl = data.image;
      _name = data.name;
      _description = data.description;
    } catch (error) {
      console.log(error);
    }
  }
}

When I try to fetch a ipfs-url using 'fetch', it shows-

enter image description here

Is there any way to do this efficiently/reliably?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Thanks to @AKX for the input. Using this for now-

  if (
      isIPFS.urlOrPath(theUri) ||
      mtokenUri.startsWith('ipfs://') ||
      mtokenUri.includes('/ipfs/') ||
      mtokenUri.includes('/bafy')
     ) { 
       // parse/cat ipfs-url
       } else { 
        // parse/fetch normal-non-ipfs-url
       }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda