CORS error while upload files with a loop to Moralis IPFS

Viewed 46

I have a JS function which uploads files to Morails IPFS:

const ipfsUploadFiles = async (files) => {
    const uploadedFilesIpfsUrls = [];
    for (var i = 0; i < files.length; i++) {
        const file = files[i];
        const ipfsFile = new Moralis.File(file.name, file);
        console.debug(ipfsFile);
        await ipfsFile.saveIPFS(); // error happens here
        const ipfsFilePath = ipfsFile.ipfs();
        const fileInfo = { id: i + 1, fileName: file.name, url: ipfsFilePath };
        uploadedFilesIpfsUrls.push(fileInfo);
        console.log(`Successfully uploaded file`, fileInfo);
    }
    return uploadedFilesIpfsUrls;
}

The first few files get uploaded successfully, but soon I start to get a CORS exception. (hidden links and server url). CORS errors

There are two requests to the server, preflight succeeds, but then thre real request fails. After that, all request fail. The uploading file is visible in payload and has a value written in base64 property. The size of the file is 9.4MB. The request response code is 502.

I tried to add some delay in the upload function loop, but I got same results. I also tried to change the site address from localhost:30000 to 1270.0.0.1:3000 but it's the same. The third thing that I checked was an article on Morails about CORS, but it is not helpfull. When I wrapped the call into a try-catch, I got this message:

Error: XMLHttpRequest failed: "Unable to connect to the Parse API"

Is there any limitation on the Morails service that is not described? Sould I just disable cors in my browser?

Used versions:

  • Moralis server version: v0.0.385
  • Environment: Ganache
  • Moralis NPM package (The Moralis JavaScript SDK): 1.11.0 (tried also 0.0.176)
  • React Morails NPM package: 1.4.2 (tried also 0.3.11)
1 Answers

Hi it looks to be a general server issue (could be resources related) looking at the last Parse API error, which will happen if the server is not reachable/unresponsive.

You could try adding delays e.g. with setTimeout for each upload (saveIPFS()).

If you have more questions or issues with this, please post with more details (including server / dapp URL) on:

Moralis forum: https://forum.moralis.io

Related