I am trying to upload image to firebase storage or firestore and i am getting the following error:
{"code_": "storage/invalid-argument", "message_": "Firebase Storage: Invalid argument in
put
at index 0: Expected Blob or File.", "name_": "FirebaseError", "serverResponse_": null}
how can I resolve this?
I know I have to convert the image to file or blob format,
but how can I do this, in this case??
PS: I am NOT using EXPO
below is my function that takes the image
const handleSelectPicture = useCallback(() => {
ImagePicker.showImagePicker(
{
noData: true,
title: 'Selecione a foto desejada',
cancelButtonTitle: 'Cancelar',
takePhotoButtonTitle: 'Usar câmera',
maxWidth: 800,
maxHeight: 800,
chooseFromLibraryButtonTitle: 'Escolher da galeria',
},
response => {
if (response.didCancel) {
return;
}
if (response.error) {
Alert.alert('Erro ao fazer upload da foto, tente novamente.');
return;
}
console.log('image: >>>> ', response.uri);
setImageURI({ uri: response.uri });
console.log('State uri>>>>', imageURI);
},
);
}, [imageURI]);
below is how I Am trying to upload that image to firebase:
await firebase
.auth()
.createUserWithEmailAndPassword(
email,
password,
)
.then(async auth => {
console.log('valueee', auth);
await db
.collection('users')
.doc('userData')
.set({
photo: imageURI,
document: params.fileSelected,
address: [data],
});
firebase
.storage()
.ref(`users/${auth.user.uid}/profileImage.jpg`)
.put(imageURI.uri)
.then(() => {
setUser(auth);
});
})