Created
December 10, 2019 17:38
-
-
Save calderaro/a0c939b03b1c0d01f447fc8e1ff96313 to your computer and use it in GitHub Desktop.
Upload File to google storage from React native
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
changeProfileImage = async e => { | |
const metadata = { cacheControl: 'public,max-age=300', gzip: true }; | |
const uid = this.state.user.uid; | |
const response = await fetch(e.uri); | |
const blob = await response.blob(); | |
const imageRef = this.storage.child(`profileImages/${uid}.png`); | |
const uploadTaskSnapshot = await imageRef.put(blob, metadata); | |
const photoURL = await uploadTaskSnapshot.ref.getDownloadURL(); | |
await this.state.user.updateProfile({ photoURL }); | |
this.setState({ user: firebase.auth.currentUser }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment