This is my React State
this.state = {
data : {
employee_Name:"" ,
employee_Id:"",
employee_Doj:"",
employee_ResumeFile:""
}
}
I am getting uploaded file data on change
onChangeHandler=event=>{
const data = { ...this.state.data };
data.employee_ResumeFile = event.target.files[0];
this.setState({ data });
console.log(data);
}
How to add this to my axios along with existing state data
doSubmit() {
// How to add this form data inside my axios
const data = new FormData()
data.append('file', this.state.data.employee_ResumeFile)
axios.put(apiEndpoint+'/update/'+this.props.match.params.id+'/basic-details',{
employee_Name:this.state.data.employee_Name,
employee_Id: this.state.data.employee_Id,
employee_Doj:this.state.data.employee_Doj,
employee_ResumeFile.state.data.employee_ResumeFile
})
}
Should we use only formdata() to send file if then how to add formdata value inside my axios with existing values
let formData = new FormData(); formData.append('file', this.state.data.employee_ResumeFile); formData.append(employee_Name,this.state.data.employee_Name); ...