Site icon Hip-Hop Website Design and Development

How you can ship multipart type knowledge to WordPress endpoint

I constructed customized React/Gatsby multipart type with file add and I wish to ship all type knowledge to WordPress endpoint, add recordsdata to particular folder and show all the knowledge within the WordPress backend.

That is how I ship knowledge:

const {
    stepOne,
    stepTwo,
  } = useContext(FormStepProvider)

  const steps = {
    stepOne: stepOne,
    stepTwo: stepTwo,
  }

  const postData = async () => {
    const formData = new FormData()

    formData.append("stepOne", JSON.stringify(stepOne))
    formData.append("stepTwo", stepTwo.file)

    await fetch("https://panel.domain.com/wp-json/test/v1/forms", {
      methodology: "POST",
      headers: {
        "Content-Type": "multipart/form-data",
      },

      physique: formData,
    })
      .then(response => response)
      .then(outcome => {
        console.log("Success:", outcome)
      })
      .catch(error => {
        console.error("Error:", error)
      })
  }

  useEffect(() => {
    postData()
    console.log(steps)
  }, [])

That is the response I get:

That is my endpoint:

add_action( 'rest_api_init', operate () {
  register_rest_route( 'take a look at/v1', 'kinds', array(
    'strategies' => 'POST',
    'callback' => 'get_formdata_function',
    'args'     => array(),
  ) );
} );

operate get_formdata_function(WP_REST_Request $request)
{
    $knowledge = $request->get_body();
    print_r($knowledge);
}

I am new to WordPress and I wish to know what’s the easiest way to do that?