[SOLVED] Ipfs uploadFolder

in documentation, the uploadFolder waits for a parameters (options) - https://v1docs.moralis.io/moralis-dapp/web3-api/ipfs-storage-new#uploadfolder-new

but in code (react-moralis 1.4.2) uploadfFolder does not expect any parameter. What it is the actual format? Where should we define the options object if it is no longer accepted in upload folder?

import { useMoralisWeb3Api } from “react-moralis”;
const Web3Api = useMoralisWeb3Api();
const path = await Web3Api.storage.uploadFolder(options);

There is a react-moralis code sample on that page:

import React from "react";
import { useMoralisWeb3Api } from "react-moralis";

const Web3Api = useMoralisWeb3Api();

const uploadFolder = async () => {
  const options = {
    abi: [
      {
        path: "moralis/logo.jpg",
        content:
          "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3",
      },
    ],
  };
  const path = await Web3Api.storage.uploadFolder(options);
  console.log(path);
};

Or are you saying you’re getting an error when you try to use something like this?

yes, using this example… uploadFolder expects no arguments

this is only an error for types or it doesn’t work if you provide those parameters?

It is a real error, the uploadFolder() method works only without arguments. If I use it like uploadFolder(options) then I get the below error - which is normal. So the current documentation is no longer synced with the actual code, and more, the actual code is pretty weird, I don’t figure out how else I can set the “options” property.

what version or Moralis SDK are you using? you are using react moralis with a moralis server or with a self hosted server?

a self hosted server (running actually locally right now)

“moralis-v1”: “^1.11.0”,
“react”: “^18.2.0”,
“react-moralis”: “^1.4.2”,

you can try moralis-v1 1.12.0 and after that you can try to call a cloud function that does that upload folder functionality directly in cloud code

what exactly this cloud function should contain?
or do you mean to use axios and simulate what uploadFolder() is supposed to do?

I don’t mean to use axios, you could try that too, I mean to call uploadFolder in a cloud function and then to call that cloud function from front end

I feel like I have to renounce for now and come back in several months. It seems that the self hosted server is not yet ready to be used by the large public. The documentation is still not updated, every 5 minutes I find something that is not reliable or well documented.

for example regarding the cloud code I found some examples to use:
const path = await Moralis.Web3API.storage.uploadFolder(options);
but I get the error “Moralis is undefined”.

you may have to import Moralis in cloud code, when you self host you can import any packages that you need in cloud code

This is just a type error, it should still work. You can change your local react-moralis types in node_modules/react-moralis/lib/hooks/core/useMoralisWeb3Api/useMoralisWeb3Api.d.ts and restart your React server (or do something similar):

storage: {
        uploadFolder: () => Promise<{

To:

storage: {
        uploadFolder: (options = {}) => Promise<{

Where exactly did you try to use this code?

1 Like

in build/cloud/main.js

did you import Moralis there in that cloud code file?

it worked like this. thank you. anyway, I hope that pretty soon we should see this change directly in the react-moralis package, just to avoid linking our code to a custom fork.