Error saving file to IPFS from cloud functions

Hey guys,

I was trying to save a file to IPFS from cloud functions but I’m getting the error ā€œfileToSave.saveIPFS is not a functionā€.

const fileToSave = new Moralis.File("image", {base64: image}, imageType);
await fileToSave.saveIPFS();

Am I missing something?

Thanks in advance!

1 Like

It looks like I get the same error, we’ll have to investigate more.

Any update on this? I’m getting the same issue.

now you can upload to IPFS from cloud code with a different syntax: https://docs.moralis.io/moralis-server/cloud-code/cloud-functions#ipfs

1 Like

Many thanks @cryptokid. That worked after a couple of goes.

I’m successfully writing files to IPFS from Cloud Code but now I’m not sure that it’s suitable for my needs. I want to be able to generate a new NFT with token ID and mint it to an ERC1155 contract. Since you can’t set the URL of the metadata to something predictable you can’t create an ERC1155 contract with the URI in a set form. So I have been experimenting with Moralis.File() and, again, the .json file name gets a ā€œrandomā€ string put before the file name in the URL. E.g.
https://blahblahblah.usemoralis.com:2053/server/files/asdgasdgasgd/long unpredictable hex string_0000000000000000000000000000000000000000000000000000000000001292.json

Is there a way of writing a file, with a name of my choosing, to a predictable location with a predictable URL, from Cloud Code, on my Moralis server so I can feed it into an ERC1155 contract? If not, do I need to set up a third-party transaction to store my metadata on AWS or similar?

It may be easier to use other hosting for the metadata json files if you don’t know from the start all the data for all of them.