[SOLVED] .saveIPFS problem

Hey all im trying to save a file via file.saveIPFS();
unfortunately im getting the error message:

i tried the other version of initializing moralis as follows:

but it throws this error:

is something going on with save.ipfs or is it in my code?

async function createItemNFT() {
      if(createItemFile.files.length == 0){
        alert ("please select file");
        return;
      }else if (createItemName.value.length == 0){
        alert ("please select name for file");
        return;
      }

      const nftFile = new Moralis.File("nftFile.jpg", createItemFile.files[0])
      await nftFile.saveIPFS();

      const nftFilePath = nftFile.ipfs();
      const nftFileHash = nftFile.hash();

      const metadata = {
        name: createItemName.value,
        description: createItemDes.value,
        nftFilePath: nftFilePath,
        nftFileHash: nftFileHash
      };
      const nftFileMetadataFile = new Moralis.File("metadata.json", {base64 : btoa(JSON.stringify(object))});
      await nftFileMetadataFile.saveIPFS();

      const nftFileMetadataFilePath = nftFileMetadataFile.ipfs();
      const nftFileMetadataFileHash = nftFileMetadataFile.hash();

      const Item = Moralis.Object.extend("Item");

      const item = new Item();
      item.set("name", createItemName.value);
      item.set("description", createItemDes.value);
      item.set("nftFilePath", nftFilePath);
      item.set("nftFileHash", nftFileHash);
      item.set("metadataFilePath", nftFileMetadataFilePath);
      item.set("metadataFileHash", nftFileMetadataFileHash);

      await item.save();
      console.log(item);
    }

thanks for your help as always!

It looks like you are using an older version of Moralis SDK
you can use this for latest version:
<script src="https://npmcdn.com/[email protected]/dist/moralis.js" ></script>

thats it!! thank you

RESOLVED

1 Like