File upload in React using formik and laravel as a backend

Viewed 17

I am new to react and I am trying to upload a file to my project. All is going well except when I am sending a file request to the backend it shows empty [] to that particular file.

This is how I am trying to send the value. In this values consists of an object of all the input fields in my form whose initial values are set as null.

const initialValues = {
    fy_id: "",
    main_chalani_no: "",
    section_chalani_no: "",
    department_id: "",
    chalani_basis: "",
    darta_id: "",
    main_chalani_date: "",
    section_chalani_date: "",
    letter_no: "",
    letter_date: "",
    chalani_office: "",
    subject: "",
    chalani_type: "",
    chalani_medium: "",
    medium_dtl: "",
    file_one: "",
    file_two: ""
};


<input className="form-control" name="file_one" type="file"
  onChange={e => {
               if (e.target.files && e.target.files.length > 0) 
                  {
                    setAvatarPreview(URL.createObjectURL(e.target.files[0]));
                   }
                  console.log(e.currentTarget.files[0]);
                  values.file_name = e.currentTarget.files[0];
                   }}
 />

Console.log is returning the file Console.log ss

And in the laravel I can get all the values but not file die and dump ss

If anybody could help me out I would be grateful and sorry for my question if I had made mistakes on them and could not make it clear as possible

0 Answers
Related