I try to show image in my react-native app. I've uploaded photo into my Firebase Storage and it's work. Then i try to display my image from Firebase Storage, but the file is blob. I want to convert blob to image but i don't know the syntax. Might be one of you could help me to solve this.
where should i place RNFetch blob? I've tried to place inside componentWillMount and it show error.
uploadImage(uri, mime = 'application/octet-stream') {
return new Promise((resolve, reject) => {
const uploadUri = uri
let uploadBlob = null
const imageRef = firebase.storage().ref('profileImg').child(`${this.state.user.uid}/Profile Image - ${this.state.user.uid}`)
fs.readFile(uploadUri, 'base64')
.then((data) => {
return Blob.build(data, { type: `${mime};BASE64` })
})
.then((blob) => {
uploadBlob = blob
return imageRef.put(blob, { contentType: mime })
})
.then(() => {
uploadBlob.close()
return imageRef.getDownloadURL()
})
.then((url) => {
console.log(url)
resolve(url)
})
.catch((e) => {
console.log(e)
reject(e)
})
})
}
getProfileImage(){
let options = {
title: 'Choose Photo',
storageOptions: {
skipBackup: true,
path: 'images'
}
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', 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 {
let image_uri = { uri: 'data:image/jpeg;base64,' + response.data };
this.uploadImage(response.uri)
.then((url) => {
console.log('uploaded')
this.setState({
image_uri: url,
});
})
.catch((error) => console.log(error))
firebase.auth().currentUser.updateProfile({
photoURL: this.state.image_uri
});
}
})
}