I’m building a react native app with firebase storage and i’m trying to 1) store the image in storage, 2) retrieve downloadURL, 3) set the downloadURL string in firebase for access via the database
storage().ref('users').child(userKey + '/profileImage').put(image.path).then(() => {
storage().ref('users').child(userKey + '/profileImage').getDownloadURL().then(image => {
setProfileImage(image)
firestore().collection('users').doc(userKey).set({
profileImage: image
}).catch((e) => console.log('uploading image error1 => ', e));
}).catch((e) => console.log('uploading image error2 => ', e));
}).catch((e) => console.log('uploading image error3 => ', e));
2
Answers
What value and type is your
image.path
variable. If you look at the documentation forReference.put
you can see that it acceptsBlob | Uint8Array | ArrayBuffer
and I somewhat doubt thatimage.path
is one of those types.image.path
is reference to device storage and not contains actually image data.Assume that
image.path
is reference of image to device storagelike
file://path/to/file
.It required to fetch image raw data either as Blob | Uint8Array | ArrayBuffer.
For Sake of simplicity, let fetch image raw data as BLOB.