I'm new to Reactjs, my objective is to upload the file by giving the pathname (Ex: //downloads/users/image.jpg/) in my form. Though i was new to this platform, Couldn't bale to figure it out where i'm going wrong.
Here is the code of Form Submit:
handleSubmit = e => {
e.preventDefault();
const { firstName, LastName, phoneNumber, file} = this.state;
const data = {
firstName,
lastName,
phoneNumber,
file
};
axios.post(`/api/Form`, data, {
headers: { 'Content-Type': 'application/json' }
})
.then(res => {
console.log(res)
console.log(res.data);
})
.catch((err) => {
console.log(err)
})
Can anyone help me in this query?
<form onSubmit={this.handleSubmit}>ReactJS Forms If not, then your handleSubmit function would not be called and there would not be any data in your post request.