Cloud functions - Web3API.uploadFolder

I’m trying to upload to IPFS through cloud functions so I can validate the content before allowing it on my app.

If I upload a file below 8MB it works fine, however It starts stalling if it’s around 10MB or above.

It also doesn’t throw an error, it simple stalls until it timeouts.

Code:

const options = {
  abi: [
    {
      path: "posts/post."+fileType,
      content: fileBase64,
    },
  ],
};
await Moralis.Web3API.storage.uploadFolder(options);

EDIT:
Looks like Moralis.Cloud.toIpfs has the same problem

IPFS files seem to be uploading ok. Tested with around 14MB.

Did the upload get successful after some time?

1 Like

uploadFolder should work with 10MB too

1 Like

Hey @johnversus thanks for the reply!

Did you upload through cloud functions tho? Because if I upload it through the client it works fine, my error is in cloud functions.

However I need to make some validation before uploading, so client upload isn’t really an option

Maybe there is a limit to the data that can be processed/uploaded through cloud code. Not quite sure on this.
It doesn’t seem like an issue with IPFS.

There are 2 options to upload from cloud code. There is a syntax specific to cloud code for IPFS and you can also use web3api upload folder functionality in cloud code. What did you use?

Tried both and both have the same issue.
A bit above 8MB it starts stalling, the promise doesn’t return nor throw, it just stalls until it timeouts.

The code you need to replicate it is literally just the upload function and a file big enough (10MB or above should do). (I’ll share the code I used to be clear)

try {
  fileToSave = await Moralis.Cloud.toIpfs({
    sourceType: "base64Binary",
    source: fileBase64,
  });
} catch(error) {
  throw "Failed to save post to IPFS. INFO: "+e.message;
}

OR

try {
  const options = {
    abi: [
      {
        path: "posts/post."+fileType,
        content: fileBase64,
      },
    ],
  };

  fileToSave = await Moralis.Web3API.storage.uploadFolder(options);
} catch (e) {
  throw "Failed to save post to IPFS. INFO: "+e.message;
}

I would expect that first option to work with bigger sizes.

What timeout it has, it replicates every time?

The experience I had was that It does replicate every time. If the file is large enough to fail, then it will fail every time. I tested around 3-5 times with failing files and they never went through.

A file with 7.6MB will instantly upload, just a couple seconds and it’s done. But a file with 11.9MB already stalled forever until I restart the server.

(After a couple of minutes I got a 504 error in the console tho so I assumed it timed out, but the server looks like it’s still processing it? Not sure about this tho)