[SOLVED] Error when running music.js file: Request body larger than maxBodyLength limit

I ran this code yesterday on the mumbai testnet and worked fine… now it’s giving mke this error after I set up a new server on the mainnet. Am I missing something? Do I need to use a different API key rather than default?

Erorr:

PS C:\Album> node music.js
Error [ERR_FR_MAX_BODY_LENGTH_EXCEEDED]: Request body larger than maxBodyLength limit
at RedirectableRequest.write (C:\Album\node_modules\follow-redirects\index.js:102:24)
at RedirectableRequest.end (C:\Album\node_modules\follow-redirects\index.js:127:10)
at dispatchHttpRequest (C:\Album\node_modules\axios\lib\adapters\http.js:401:11)
at new Promise ()
at httpAdapter (C:\Album\node_modules\axios\lib\adapters\http.js:48:10)
at dispatchRequest (C:\Album\node_modules\axios\lib\core\dispatchRequest.js:58:10)
at Axios.request (C:\Album\node_modules\axios\lib\core\Axios.js:108:15)
at Axios. [as post] (C:\Album\node_modules\axios\lib\core\Axios.js:140:17)
at Function.wrap [as post] (C:\Album\node_modules\axios\lib\helpers\bind.js:9:15)
at C:\Album\music.js:24:6 {

music.js:

let fs = require(“fs”);

let axios = require(“axios”);

let media = [“albumcover.png”, “FUNGKU.wav”, “Holes.wav”];

let ipfsArray = [];

let promises = [];

for (let i = 0; i < media.length; i++) {

promises.push(

new Promise((res, rej) => {

  fs.readFile(`${__dirname}/export/${media[i]}`, (err, data) => {

    if (err) rej();

    ipfsArray.push({

      path: `media/${i}`,

      content: data.toString("base64"),

    });

    res();

  });

})

);

}

Promise.all(promises).then(() => {

axios

.post("https://deep-index.moralis.io/api/v2/ipfs/uploadFolder", ipfsArray, {

  headers: {

    "X-API-KEY":

      "I put Default API Key here",

    "Content-Type": "application/json",

    accept: "application/json",

  },

})

.then((res) => {

  console.log(res.data);

})

.catch((error) => {

  console.log(error);

});

});

I really appreciate if someone could help with this! :slight_smile:

Maybe the file size is somehow bigger now.
What is the size of the file files that you try to upload to IPFS?

That was it! Just needed to convert wav files to mp3 and it worked! :slight_smile:

1 Like

what is the file size limit for images?

Hi,

A file size of 10-20MB should work fine when uploading it to IPFS with any endpoint.

Sincerely,

Crypto Kid | Technical Support