Working with Firebase.storage() - Hemantsaraf08/rollingstones GitHub Wiki

const uploadTaskListener = storage.ref(/user/${uid}/profileImage).put(file); //here file is stored in state

        uploadTaskListener.on("state_changed", fn1, fn2, fn3);
        // Register three observers:
        // 1. 'state_changed' observer, called any time the state changes
        // 2. Error observer, called on failure
        // 3. Completion observer, called on successful completion
        // fn 1 -> progress tracking
        // fn2 -> error
        // fn3 -> success

       function fn1(snapshot) {
           //snapshot is given by firestore and applies to both image and audio all file types
           let progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
           console.log(`Upload is ${progress}% done`);
       }


       function fn2(error) {
           setError(error);
           setTimeout(() => {
           setError('')
           }, 2000);
           setLoading(false)
      }

       async function fn3() {
              //on success
              let downloadUrl = await uploadTaskListener.snapshot.ref.getDownloadURL();//snapshot means any file audio, video, image==> given by firebase
              console.log(downloadUrl);
             //BELOW WE DO WORK FOR firebase.firestore EXPLANED IN NEXT PAGE   
          }
⚠️ **GitHub.com Fallback** ⚠️