vendredi 23 décembre 2016

Firebase Storage Web: How to upload a file

I added the following function to my website. I am using Firebase Storage but for some reason it seems as if it is not working and I have no idea why.

When you upload a file the progress bar should show the progress of saving/uploading the file to Firebase Storage but that is not the case. Firebase has been initialized and I know it works.

I would greatly appreciate if someone could help me and tell me why the function is not working as described above and how to fix it.

function AddMed() {
        var uploader = document.getElementById("uploader");
    var fileButton = document.getElementById("fileButton");
    var email = sessionStorage.getItem("email");
  //Listen for file selection

    fileButton.addEventListener('change', function (e) {
    // Get File 
        var file = e.target.files[0];
    //Create a storage ref

        var storageRef = firebase.storage().ref('file/' + file.name);
    /** folder name will be email, 
    Will have to transfer variable from page to page and files will be .jpeg**/
    //Upload file 

        var task = storageRef.put(file);
    //Update progress bar

        task.on('state_changed',
                function progress(snapshot) {
                var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
                uploader.value = percentage;
            },
            function complete() {

                    });
    });

}




Aucun commentaire:

Enregistrer un commentaire