Reputation: 37
i am trying to append image with form data the problem is that if image is not passed i get error submitted data is not file
because image is passed as undefined
const formData = new FormData();
formData.append("image", image);//if image is empty dont append image with form data
Object.entries(Data).forEach(([key, value]) => formData.append(key, value));
axios.patch("url-for-api/", formData, config)
if the image is undefinnd axios patch is giving error
Upvotes: 0
Views: 188
Reputation: 46
const formData = new FormData();
for (const [key, value] of Object.entries(values)) {
if (value) {
formData.append(key, value);
}
}
axios.patch("url-for-api/", formData, config)
Upvotes: 1
Reputation: 37
const formData = new FormData(); if (image != undefined) {
formData.append("prescription", image);
}
Object.entries(Data).forEach(([key, value]) => formData.append(key, value));
axios.patch("url-for-api/", formData, config)
Upvotes: 0