Skip to content

Instantly share code, notes, and snippets.

@calderaro
Created December 10, 2019 17:38
Show Gist options
  • Save calderaro/a0c939b03b1c0d01f447fc8e1ff96313 to your computer and use it in GitHub Desktop.
Save calderaro/a0c939b03b1c0d01f447fc8e1ff96313 to your computer and use it in GitHub Desktop.
Upload File to google storage from React native
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