I'm trying to pick a photo from my gallery and upload it to the cloudinary account. The image is chosen from the gallery and when I submit it, an error comes saying "TypeError: Network request failed". The code is as follows.
const choosePhotoFromLibrary = () => {
ImagePicker.openPicker({
width: 300,
height: 300,
cropping: true,
compressImageQuality: 0.7
}).then(image => {
handleUpload(image);
bs.current.snapTo(1);
});
}
const handleUpload = (image) => {
const data = new FormData()
data.append('file', image)
data.append('upload_preset', 'tourxApp')
data.append('cloud_name', 'xxx')
fetch("https://api.cloudinary.com/v1_1/xxx/image/upload", {
method: 'POST',
body: data
}).then(res => res.json()).
then(data=>{
console.log(data);
})
.catch(e=>{
console.log(`Uploading error ${e}`)
})
}
What is wrong here and how can I fix this?