i am using formik
onSubmit={async (values) => {
const formData = new FormData();
formData.append('file', values.mediaUrl);
try {
// Make the API call to post the image
const response = await axios.post('/api/media', formData);
// Check the API response and show appropriate messages
if (response && response.status === 200) {
toast.success('Media added successfully', {
position: toast.POSITION.TOP_RIGHT,
});
} else {
toast.error('Failed to add media', {
position: toast.POSITION.TOP_RIGHT,
});
}
} catch (error) {
console.error('Error adding media:', error);
toast.error('An error occurred while adding media', {
position: toast.POSITION.TOP_RIGHT,
});
}
}}