[SOLVED] Using ipfs uploadFolder in sdk

Hi, how are you? Could you help me with this typescript error:
An argument of type “{ “0”: { path: string; content: string; }; }” cannot be assigned to parameter of type “UploadFolderRequest”.
The object literal can only specify well-known properties and ‘“0”’ does not exist on type ‘UploadFolderRequest’.

const response = await Moralis.EvmApi.ipfs.uploadFolder({

    "0": {

      "path": "moralis/logo.jpg",

      "content": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3"

    }

  });

  console.log('response :', response);

ok remove the error like this:


const fileUpload = [
    {
      path: "moralis/logo.jpg",
      content: content
    }
  ]

  const response = await Moralis.EvmApi.ipfs.uploadFolder({
    abi: fileUpload
   });

Hi @davidzuccarini

Yeah you need to update it using the ABI param. The code shown in the docs is auto-generated so it generates differently for this. :sweat_smile:

In SDK it should look like this.

Moralis.EvmApi.ipfs.uploadFolder({
    abi: [
      {
        path: "moralis/logo.jpg",
        content:
          "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3",
      },
    ],
  });

hello, i have this issue : errorIPFS Moralis SDK Core Error: [C0006] Request failed: timeout of 20000ms exceeded

try{

    if(ifNft){

     const abi: any  = [
        {
            path: contentName,
            content: {
              name: content.name,
              description: content.description,
              image: content.image,
              attributes: [
                {
                  "trait_type": "energy",
                  value: content.energy
                },
                {
                  "trait_type": "force",
                  value: content.force
                },
                {
                  "trait_type": "impact",
                  value: content.impact
                },
                {
                  "trait_type": "sustainability",
                  value: content.sustainability
                },
                {
                  "trait_type": "value",
                  value: content.valueNft
                },
                {
                  "trait_type": "rarity",
                  value: content.rarity
                },
                {
                  "trait_type": "type",
                  value: content.type
                },
              ]
            },
        },
      ];


      const response = await Moralis.EvmApi.ipfs.uploadFolder({ abi });

     

      console.log('responseUrlIpf', response);

      const responseUrl = response.raw

      const path = responseUrl[0].path

      const hash = removeBaseUrl(path);

      return { path, hash}

    }else{

      const base64Data = await readAsBase64(content)  as string;

      const fileUpload = [

        {

          path: `${ethAddress}/${contentName}`,

          content: base64Data.toString()

        }

      ]

      const response = await Moralis.EvmApi.ipfs.uploadFolder({

        abi: fileUpload

      });

      const responseUrl = response.raw

      const path = responseUrl[0].path

      const hash = removeBaseUrl(path);

      console.log('responseUrl :', responseUrl);

      return { path, hash}

    }

  }catch(error: any){

    console.error("errorIPFS", error)

  }

all variables have data ethAddress: have a wallet, content has :

{
    "name": "art main",
    "description": "\"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain...\"",
    "energy": 91,
    "force": 35,
    "impact": 100,
    "sustainability": 81,
    "value": 81,
    "rarity": 44,
    "type": "CommonEggs",
    "image": "https://ipfs.moralis.io:2053/ipfs/QmYU2QWwaq5wYybTVa8CBZT8gkMDvXNcTHbKg1Lxq29AkS/0xa136632e5123be81d620ecbdf5669741e32e3d75/arte.jpg",
    "imageHash": "QmYU2QWwaq5wYybTVa8CBZT8gkMDvXNcTHbKg1Lxq29AkS/0xa136632e5123be81d620ecbdf5669741e32e3d75/arte.jpg"
}

they all have data. please help

sorry it was the toString(), solved.

1 Like