You can post axios data by using [FormData()][1] like :
var bodyFormData = new FormData();
And then add the fields to the form you want to send :
bodyFormData.set('product', productName);
If you are uploading single file, you may want to use `.append`
bodyFormData.append('file',file);
And then you can use axios post method (You can amend it accordingly)
axios({
method: 'post',
url: 'myurl',
data: bodyFormData,
headers: {'Content-Type': 'multipart/form-data' }
})
.then(function (response) {
//handle success
console.log(response);
})
.catch(function (response) {
//handle error
console.log(response);
});
You can read more [Here][2]
[1]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
[2]: https://github.com/axios/axios/issues/318
You can post axios data by using [FormData()][1] like :
And then add the fields to the form you want to send :
let bodyFormData = new FormData();
bodyFormData.set('email',this.state.email);
bodyFormData.set('password', this.state.password);
And then you can use axios post method (You can amend it accordingly)
axios({
method: 'post',
url: 'http://127.0.0.1:8000/api/login',
data: bodyFormData,
config: { headers: {'Content-Type': 'multipart/form-data' }}
})
.then(function (response) {
//handle success
console.log(response);
})
.catch(function (response) {
//handle error
console.log(response);
});
[1]: https://developer.mozilla.org/en-US/docs/Web/API/FormData