​https://firebase.google.com/docs/storage/web/upload-files​
On React client
const handleUpload = () => {const selectedFile = selectedFiles[0];​// Create a root referenceconst storageRef = firebase.storage().ref();// Create a reference to 'mountains.jpg'const fileRef = storageRef.child('test.txt');const uploadTask = fileRef.put(selectedFile).then(function(snapshot) {// TODO: add some kind of alert confirming upload of file// TODO: when choosing file, have a upload option?console.log('Uploaded a blob or file!', snapshot);});// uploaded filesetShowNotice(true);};
const handleUpload = () => {const selectedFile = selectedFiles[0];​// Create a root referenceconst storageRef = firebase.storage().ref();// Create a reference to 'mountains.jpg'const fileRef = storageRef.child('test.txt');const uploadTask = fileRef.put(selectedFile).then(function(snapshot) {// TODO: add some kind of alert confirming upload of file// TODO: when choosing file, have a upload option?console.log('Uploaded a blob or file!', snapshot);});// https://firebase.google.com/docs/storage/web/upload-files// Listen for state changes, errors, and completion of the upload.uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'function(snapshot) {setIsUploading(true);// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploadedvar progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;console.log("Upload is " + progress + "% done");// TODO: function to update progress bar using percentagesetUploadProgress(progress);switch (snapshot.state) {case firebase.storage.TaskState.PAUSED: // or 'paused'console.log("Upload is paused");break;case firebase.storage.TaskState.RUNNING: // or 'running'console.log("Upload is running");break;default:console.error('Error with upload to firebase');break;}},// error handlingfunction(error) {setIsUploading(false);// A full list of error codes is available at// https://firebase.google.com/docs/storage/web/handle-errorsswitch (error.code) {case "storage/unauthorized":// User doesn't have permission to access the objectconsole.error(error.code);break;case "storage/canceled":// User canceled the uploadconsole.error(error.code);break;case "storage/unknown":// Unknown error occurred, inspect error.serverResponseconsole.error(error.code);break;default:console.error('Error with upload to firebase', error);break;}},// upload completedfunction() {// Upload completed successfully, now we can get the download URLuploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {// upload filesetShowNotice(true);console.log("File available at", downloadURL);setDownloadURL(downloadURL);});});​// uploaded filesetShowNotice(true);};
​How does Firebase associate uploaded files with a specific user?​
​Create a reference to a Cloud Storage document in Firestore​
TODO: add logic to do progress bar of file
​