I am currently developing a project using react-native and I am facing an issue with uploading an image to Firebase using Firebase Storage. To select the image from the phone, I am utilizing react-native-image-picker, which provides me with the base64 encoded data.
However, when attempting to upload the image to Firebase, I encounter the error message
Firebase Storage: String does not match format 'base64': Invalid character found
, despite verifying that the string is indeed a valid base64 string using regex.
Although I have researched several solutions, none seem to resolve the issue. Here is the code I am using:
function uploadImage(image){
const user = getCurrentUser();
const refImage = app.storage().ref(`profileImages/${user.uid}`);
refImage.putString(image, 'base64').then(() => {
console.log('Image uploaded');
});
}
This is how I implement the image picker:
ImagePicker.showImagePicker(ImageOptions, (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
uploadImage(response.data);
}
});