We can pass headers as arguments,
onClickHandler = () => {
const data = new FormData()
for(var x = 0; x<this.state.selectedFile.length; x++) {
data.append('file', this.state.selectedFile[x])
}
const options = {
headers: {
'Content-Type': 'application/json',
}
};
axios.post("http://localhost:8000/upload", data, options, {
onUploadProgress: ProgressEvent => {
this.setState({
loaded: (ProgressEvent.loaded / ProgressEvent.total*100),
})
},
})
.then(res => { // then print response status
console.log('upload success')
})
.catch(err => { // then print response status
console.log('upload fail with error: ',err)
})
}