I'm trying to upload images to Cloudinary from my React Native app, but I'm getting the "400 Bad Request" saying the image I'm sending is ""x-cld-error": "Unsupported source URL".
ImageUpload.js
const pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1
})
if (!result.cancelled) {
setImageSource(result.uri);
}
}
I'm currently using the ImagePicker
from expo-image-picker
. I'm taking the imageSource
I've obtained from above and appending it to data before sending it to Cloudinary. The result.uri
shows the URL of the picture from the iOS simulator.
CreatePost.js
const uploadFile = async () => {
const data = new FormData();
data.append('file', imageSource);
data.append('upload_preset', 'test_folder')
const res = await fetch('https://api.cloudinary.com/v1_1/{my_cloudinary}/image/upload', {
method: 'POST',
body: data,
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
},
})
const file = await res.json()
setImage(file.secure_url)
setLargeImage(file.eager[0].secure_url)
}
When I console.log res
, it shows that the status is 400.
imageSource
in the same function you're performing the Upload request to Cloudinary? I ask that because when this error is returned it includes the start of the source that was used, but in your question, that's not included. For example,Unsupported source URL: data:;base64,
orUnsupported source URL: Object(...
. – Aleksandar