IPFS - Maximum call stack size exceeded

Usually, you get that error when the wrong type of data is sent, like a variable instead of a value.

Can you add some logging? Like logging the size of the sent data?

1 Like

I have a limit of 8mb before the upload so I know the size isn’t the problem.
Either ways I printed out the actual size.
5799702 ~= 5MB

ok, and that data makes it to the cloud function, an the cloud function gives that particular error?

1 Like

Exacly that yes,

The line that fails is the one that tries to upload the file to the IPFS

const fileToSave = await Moralis.Cloud.toIpfs({
    sourceType: "base64Binary",
    source: imageBase64,
});

ok, got it, I’ll have to test it today/tomorrow to see how it repicates

that link (https://i.ibb.co/6v4BPrW/1.png) points to a ~4MB file

1 Like

Oh mb, 5799702 is the number of chars in the string, I usually calculate the size by multiplying by 3/4. ~= 4349776 bytes ~= 4.1483 Megabytes

That’s the correct image and the size on the client is exactly the same when it reaches the server

I get a smaller size for the original file and also for the base64 encoding, maybe you also have the file name there?

If you’re getting 4349760 then that’s the true size, 4349776 is just an estimation

I was able to reproduce the error

1 Like

Awesome, now the hard part comes, why is it happening

Hey again,
Have you got any news about this issue?

I don’t know yet. It looks to be related to a library that checks that base64 buffer. You could try to use upload folder functionality from web3api as an alternative.

Hey @cryptokid!

Just wanted to know if we should start using the ā€œupload folderā€ functionality everywhere instead of the ā€œoriginalā€ way or if it’s going to get fixed at some point!

You can try uploadFolder functionality, I don’t know when it will be fixed.

Thanks for the reply,
Is uploadFolder compatible with other ipfs gateways (beyond moralis ones)?

Like ā€œhttps://infura-ipfs.io/ipfs/ā€ for instance

yes, it is compatible with the other ipfs gateways.

Sorry for so many questions but it looks like uploadFolder can’t be used in cloud functions. Is that right?

it should work without problems, it is only a web3api call, you can also call it directly has REST api

1 Like

So web3api call works! Thanks for the help.

I still personally prefer using normal hash without the ā€œfolder/filenameā€ at the end. This way I could find duplicates easily, because same file generates same ipfs hash.
Correct me if I’m wrong but this isn’t possible with web3api (I suppose) because it uploads a folder instead of a single file.

Meanwhile I got some more examples that break ā€œMoralis.Cloud.toIpfsā€ that my users found while trying to upload images to the dapp.

https://ufile.io/dlh55d4h (4 images total, for now, from +500 images posted)

you can use same folder and file path for all the uploaded files, like /a/b.c