Make sure to have a header with 'content-type': 'multipart/form-data'
_handleSubmit(e) {
e.preventDefault();
const formData = new FormData();
formData.append('file', this.state.file);
const config = {
headers: {
'content-type': 'multipart/form-data'
}
}
axios.post("/upload", formData, config)
.then((resp) => {
console.log(resp)
}).catch((error) => {
})
}
_handleImageChange(e) {
e.preventDefault();
let file = e.target.files[0];
this.setState({
file: file
});
}
#html
<input className="form-control"
type="file"
onChange={(e)=>this._handleImageChange(e)}
/>