I try to upload a "base64" image to Firebase by using React Native on iOS. But when I try to upload the image, I get following error:
Upload failed: [Error: [storage/unknown] An unknown error has occurred.
What should I do, I have tried to change the rules, but I'am not sure if they are right. I have Uninstall firebase/Storage and reinstall it again, but I get the same error.
If I run npm install I get following warning:
[!] NPM package '@react-native-firebase/storage' depends on '@react-native-firebase/app' v12.3.0 but found v12.1.0, this might cause build issues or runtime crashes.
is anyone have clue of what I should do?
const uploadImage = async () => {
const dataUrl = `data:image/png;base64,${result}`;
filename.
const childPath = `paintBoards/${
auth().currentUser.uid
}/${Math.random().toString(36)}`;
const storageRef = storage().ref(childPath);
const uploadTask = storageRef.putString(dataUrl, 'data_url');
uploadTask.on('state_changed', snapshot => {
setTransferred(
Math.round(snapshot.bytesTransferred / snapshot.totalBytes) * 10000
);
});
try {
await uploadTask;
setUploading(false);
Alert.alert(
'Photo uploaded!',
'Your photo has been uploaded to Firebase Cloud Storage!'
);
} catch (err) {
// TODO: Check value of `err.code` and handle appropriately.
console.error('Upload failed: ', err);
Alert.alert(
'Photo upload failed!',
'Your photo didn upload properly!'
);
}
}