'how to upload an image to server with other text fields
// i want to send the image to backend server and have to get data from the server and have to show the get image
const handleSubmit = async evt => {
evt.preventDefault();
const { image, name, quote, designation } = formInput;
if (name == "" && designation == "" && quote == "" && image == "") {
alert("please update input fields")
} else {
uploadFile();
formInput.image = file;
console.log(formInput);
return await axios.post("xyz/api", formInput).then(res => {
console.log(res.data);
evt.target.reset();
setFormInput({
name: "",
designation: "",
quote: "",
image: ""
})
set Choose(null);
setFileUrl(null);
}).catch(error => {
console.log((error));
})
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
