Reputation: 1375
I want to send the data to the Api as FormData I use react react-hook-form This is what I have:
const submitForm = (data) => {
console.log(data)==>{Title:"test" ,Countent:"countent"}
service.uploadFile(data, (status, result) => {
if (result.Success) {
props.notifySuccess(result.Message);
} else {
props.notifyError(result.Message);
}
});
};
How do I send data as FormData?
Upvotes: 0
Views: 104
Reputation: 770
const submitForm = (data) => {
const formData = new FormData();
Object.keys(data).forEach((ele) => formData.append(ele, data[ele]))
service.uploadFile(formData, (status, result) => {
if (result.Success) {
props.notifySuccess(result.Message);
} else {
props.notifyError(result.Message);
}
});
};
Upvotes: 1