1

I am using formdata to send images to the server but when I use the append function, it does not add anything to formdata that I have declared and I keep getting a 400 error.

const fileSelectHandler = (e) => {
    e.preventDefault();
    setFile(e.target.files[0]);

    let image = file;
    let formData = new FormData();

    formData.append("image", image);
    console.log(formData);
    
    Axios.post(imgUrl, formData, config)
      .then((response) => console.log("Response: " + response))
      .catch((err) => console.log("error: " + err));
  };

and the input:

<input
  type="file"
  className="form-control"
  onChange={fileSelectHandler}
/>
Husnain Mehmood
  • 109
  • 4
  • 13

0 Answers0