I'm trying to create a mobile application with react native and expo for the machine learning classification image. My application take photos from the camera and send the PhotoUri to a function that return the prediction. How can I convert the image uri to base 64 string?
The easiest way is to use the official expo-image-picker. The package offer option to capture image via camera or load them from the media library
import * as ImagePicker from 'expo-image-picker'
const pickImage = async () => {
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
base64:true // Return base64 image data
});
console.log(result);
if (!result.cancelled) {
//
}
}