I would like to upload a picture from Android Virtual Device to Imgur
I already saw this link.
With ImagePicker.launchImageLibraryAsync()
I get the file :
export async function pickImage() {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: false,
aspect: [4, 3],
quality: 0,
// base64: true
});
if (!result.cancelled) {
return result.uri
}
}
Now, axios instance creation :
const instance = axios.create({
baseURL: 'https://api.imgur.com/3/',
});
Now, axios POST :
async function postImage(authState, imageUri) {
//let imageData = new FormData();
//imageData.append('file', {uri: imageUri});
await instance({
method: 'post',
url: 'upload/',
data: {
image: imageUri
},
headers: {
'Authorization': 'Bearer ' + authState.accessToken,
'Content-Type': 'multipart/form-data'
},
})
.then((response) => {
console.log("========== [OK] [POST] IMAGE ==========");
})
.catch((error) => {
if (error.response) {
console.log("========== [ERROR] [POST] IMAGE ==========");
console.log(error.response.data.data.error);
} else {
console.log('Error', error.message);
}
errorObject.status = 'KO';
return errorObject;
});
}
I get this error :
========== [ERROR] [POST] IMAGE ==========
Invalid URL ({"image":"file:/data/user/0/host.exp.exponent/cache/ExperienceData/%2540Johndoe%252Fphoto_finder/ImagePicker/0b453d00-189d-4ccb-840a-6215fff97d38.png"})
- There is no error in URL (works with Postman)
- I tried the request with different Content-Type
- If I remove the "data" field, I get this error :
"error": "No image data was sent to the upload api"
I don't know what how to move on with this "Invalid URL". Can you help me please ? Thank you very much.