[SOLVED] React: URL not getting passed to my IPFS metadata upload

Hey everyone! New here, Discord support is amazing but this is a bit more complicated so posting here.

I am trying to pass the URL from my IPFS upload to my IPFS metadata but it isnโ€™t working. Can someone tell me what I am doing wrong here?

  // upload metadata
  const uploadMetadata = async (fileIpfsUrl) => {
    const name = document.getElementById("metadataName").value;
    const description = document.getElementById("metadataDescription").value;

    const metadata = {
      name: name,
      description: description,
      image: fileIpfsUrl,
    };
    const file = new Moralis.File("file.json", {
      base64: btoa(JSON.stringify(metadata)),
    });
    await file.saveIPFS();
    console.log(file.ipfs());
  };

  const handleFinal = async () => {
    const image = await saveFileIPFS(file);
    uploadMetadata();
  };

Resulted IPFS stores.

this can be closed! I figured it out. Posting here for anyone who might want to reuse the code!


  // upload to ipfs
  const saveFileIPFS = async (f) => {
    console.log("FILE", f);
    const fileIpfs = await saveFile(f.name, file, { saveIPFS: true });
    console.log(fileIpfs);
    const fileIpfsUrl = fileIpfs._url;
    console.log(fileIpfsUrl);
    return fileIpfsUrl;
  };

  // upload metadata
  const uploadMetadata = async (fileIpfsUrl) => {
    const name = document.getElementById("metadataName").value;
    const description = document.getElementById("metadataDescription").value;

    const metadata = {
      name: name,
      description: description,
      image: fileIpfsUrl,
    };
    const file = new Moralis.File("file.json", {
      base64: btoa(JSON.stringify(metadata)),
    });
    await file.saveIPFS();
    console.log(file.ipfs());
  };

  const handleFinal = async () => {
    const image = await saveFileIPFS(file);
    await uploadMetadata(image);
  };
2 Likes

Great work! :raised_hands: