i'm trying to upload a image with expo image picker and axios.
It's my code:
// Select image from Library <--comment
const selectImage = async () => {
// Get iamge
try {
// Check has library permission <--comment
const hasLibraryPermission = await requestLibraryPermision();
if (hasLibraryPermission) {
// Lunch camers <--comment
const result = await ImagePicker.launchCameraAsync();
// Check is canceld or not <--comment
if (!result.canceled) {
// Set result uri to state <--comment
const newInformation = { ...information };
newInformation.data.image = result.assets[0].uri;
setInformation(newInformation);
// Define and append result to form data <--comment
const formData = new FormData();
formData.append("image", result.assets[0]);
// Define request url <--comment
const url = `${serverData.url}/profile/update-image`;
// Send post upload image request <--comment
await axios
.post(url, formData, {
headers: {
"content-type": "multipart/form-data",
},
})
.then((response) => {
console.log("response: ", response.data);
})
.catch((error) => {
console.log("CATCH ERROR: ", error);
});
}
}
} catch (error) {
console.log("Error: ", error);
}
};
The request show this error log: CATCH ERROR: [AxiosError: Network Error]
I searched in the web and even ask at the bard and chat gpt ai's but they can't answer me, whats the problem?
A file object should have
uri,nameandtypefields, something like this: