Skip to content

Instantly share code, notes, and snippets.

@benjick
Created April 12, 2017 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjick/5b98370a92225572b7f16ce51ab8ffda to your computer and use it in GitHub Desktop.
Save benjick/5b98370a92225572b7f16ce51ab8ffda to your computer and use it in GitHub Desktop.
<input
type="file" onChange={(e) => {
const file = e.target.files[0];
const metadata = {
contentType: 'image/jpeg',
};
const imageRef = storageRef.child(`images/${file.name}`);
const uploadTask = imageRef.put(file, metadata);
uploadTask.on('state_changed', (snapshot) => {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log(`Upload is ${progress}% done`);
}, (error) => {
console.error('Image upload', error);
}, () => {
const downloadURL = uploadTask.snapshot.downloadURL;
console.log('downloadURL', downloadURL);
imageRef.getDownloadURL().then((url) => {
console.log('result', url);
});
});
}}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment