CloudFunction not saving files in IPFS

Hello,

I am trying to save a json object in the IPFS from a cloud function, but I am getting the error " Error: {“message”:“file.saveIPFS is not a function”,“code”:141}".
What am I doing wrong? Is it possible to do it from a cloud function?

I know that would be better to do it in the client side, but in this case I can not trust in the client, so I need to do it in the cloud function.

Moralis.Cloud.define("saveMetadataForNFT", async (request) => {
 
  var metadata = {
      "name" : request.params.name,
      "description": request.params.description,
      "location": request.params.location
   };

  const jsonStr = JSON.stringify(metadata);

  const data = Array.from(Buffer.from(jsonStr));
  const file = new Moralis.File('metadata_'+request.params.name, data);
  await file.saveIPFS();
 
  return {
  	"ipfsLocation": "test"
  };
});

Thanks,
Pedro

Hi pedrosantos,

The good news is it’s not you is it’s us. The bad news is that saveIFPS() is not currently supported in Cloud Functions. This is probably something that should be added, but currently this functionality is only available in the SDK- i.e. from the browser or in Nodejs.

1 Like