I'm trying to upload image from React Native app to Cloudinary.The image appears on Dashboard, but I don't get secure_url.
Here is my code:
async uploadImage(photo: ImagePickerResponse, id: string): Promise<string> { return new Promise<string>(async (resolve, reject) => { const uploadPreset = 'bbbbbb'; const cloudName = 'aaaaa'; const body = new FormData(); const uri: string = Platform.OS === 'android' ? photo.uri : photo.uri.replace('file://', ''); const type = photo.type; const name = `eMia${id}.jpeg`; const file = {uri, type, name}; body.append('file', file); body.append('upload_preset', uploadPreset); body.append('cloud_name', cloudName); const url = `https://api.cloudinary.com/v1_1/${cloudName}/image/upload`; fetch(url, {method: 'POST', body}) .then((res) => { // I don't have Body here so i don't have the image url :( console.log(res); res.json(); }) .then((json) => { console.log(json); const url = json.secure_url; console.log(url); resolve(url); }) .catch((err) => { reject(err); }); }); }
Response: