saveIPFS() function is not working as expected

Issue Description

saveIPFS() function is not saving file correctly to IPFS and since this is an issue on production I would like to fix this issue as soon as possible. thanks in advance.

const res = await file.saveIPFS()
console.log(await res.ipfs(), await res.hash())

res.ipfs() returns link to the image - i.e: https://ipfs.moralis.io:2053/ipfs/QmXs57mbGbhZiEGv3DqAJKwemi36C1TFrqyFzQd6C44B1L
instead of JSON as in this document result - https://ipfs.moralis.io:2053/ipfs/QmUfpsyqc4hwozotRo4woyi5fJqvfcej5GcFvKiWoY6xr6

Steps + code to reproduce

const file = new Moralis.File(media[0].name, media[0])
const res = await file.saveIPFS()

Actual Outcome

Getting ipfs link just returns the image instead JSON.

Expected Outcome

Get JSON object from saveIPFS() method.

Environment

Server

  • Moralis server version: 0.0.345

Client

  • Moralis SDK version: 1.3.1
  • Operating system: MacOS Monterey
  • Browser: Chrome

Logs

I think that you have to upload a json in order to return a json

Hmm… I see. But I just followed this example - https://docs.moralis.io/moralis-server/files/ipfs

Could you let me know how to upload a json?

you could try this from a cloud function: https://docs.moralis.io/moralis-server/cloud-code/cloud-functions#object

then where should I upload file?

first you upload the image to IPFS, you keep the link for the image, then you create a json file/object that contains that image link

you can upload from cloud code an image too, you already know how to do it in front end

you can also upload a json from front end, you’ll have to convert it to a string, you’ll find examples with btoa in other similar forum posts

I cannot use Moralis.Cloud.toIpfs() function. It says it’s not a function.

you may be able to use that only from cloud code

but I want to do this in the frontend side.

there is possible to do it in front end too, you can also call a cloud function in front end

what I am trying to do is just create an NFT in the frontend side using moralis and there is not clear instruction or example code in moralis documentation.

again. we don’t have any cloud function

you have to save a json file and an image to ipfs, it looks like you already managed to do one of them

yes, I was able to save image and get link to the image

const file = new Moralis.File(media[0].name, media[0])
      const res = await file.saveIPFS()

res.ipfs() returns the link to the image but what I am expecting to see is a json object which includes name, description and image because normal NFTs which I created from other platforms look like that.
we are paying paying moralis and use moralis on production but they didn’t reply me at all on github.

you have to create that json separately, something like:

metadata = {"info": "info"}
const jsonFile = new.Moralis.File("metadata.json", {base64: btoa(JSON.stringify(metadata))});
res2 = await file.saveIPFS()

Thanks @cryptokid. I was able to save and get json object and I used the response to deploy. It seems it’s showing up on opensea.io but now it’s not showing up on our app. we are using Moralis to fetch all NFTs from connected wallet. what could be the reason?

you can try to run getTokenIdMetadata for that token that you minted, it should index the contract in case that it was not already indexed

  const { data: nfts } = useNFTBalances()

I am using useNFTBalances hook to grab all NFTs. where should I should getTokenIdMetadata?

you can use it directly in admin interface in web3api tab, only until it will return some data to be sure that the contract is indexed by Moralis