Created
April 12, 2017 13:03
-
-
Save benjick/5b98370a92225572b7f16ce51ab8ffda to your computer and use it in GitHub Desktop.
This file contains 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
<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