Skip to content

Instantly share code, notes, and snippets.

@tahoeRobbo
Last active February 2, 2016 02:27
Show Gist options
  • Save tahoeRobbo/a61a5427c472c501f0c2 to your computer and use it in GitHub Desktop.
Save tahoeRobbo/a61a5427c472c501f0c2 to your computer and use it in GitHub Desktop.

Revisions

  1. tahoeRobbo revised this gist Jun 22, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion uploadImageToFirebase
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ var uploadFile = function() {
    //RUNS AFTER THE READER.READAS...(FILE) IN THE IF STATEMENT. DELIVERS RESULTS AFTER EVERYTHING IS LOADED
    //SIMILAR TO PROMISE RESOLUTION
    reader.onloadend = function() {
    var imgRef = new Firebase('https://familyalbum.firebaseio.com/photos');
    var imgRef = new Firebase('https://YOUR_APP.firebaseio.com/photos');
    imgRef.push({
    data : reader.result,
    caption : inputCaption,
  2. tahoeRobbo renamed this gist Jun 22, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. tahoeRobbo created this gist Jun 22, 2015.
    50 changes: 50 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    /*CORRECT WORKING FUNCTION TO CONVERT TO BASE 64 AND DISPLAY PREVIEW*/
    //var readFile;
    var previewFile = function() {
    var preview = document.querySelector('#preview');
    var file = document.querySelector('input[type=file]').files[0];
    var reader = new FileReader();

    reader.onloadend = function() {
    preview.src = reader.result
    }
    if (file) {
    reader.readAsDataURL(file);
    } else {
    preview.src = '';
    }
    } // previewFile()

    var uploadFile = function() {
    console.log('uploadFile Clicked')
    var file = document.querySelector('input[type=file]').files[0];
    var reader = new FileReader();
    var inputCaption = document.querySelector('#photoCaption').value;

    /* reader.onloadend = function() {
    reader.result;
    }*/

    //RUNS AFTER THE READER.READAS...(FILE) IN THE IF STATEMENT. DELIVERS RESULTS AFTER EVERYTHING IS LOADED
    //SIMILAR TO PROMISE RESOLUTION
    reader.onloadend = function() {
    var imgRef = new Firebase('https://familyalbum.firebaseio.com/photos');
    imgRef.push({
    data : reader.result,
    caption : inputCaption,
    });
    document.querySelector('#photoCaption').value = '';
    }

    //MAKES SURE THERE IS A FILE SELECTED -- IF THERE IS, READ THE FILE AS A DATAURL -- CAN ACCESS RETURN
    //VIA READER.RESULT
    if (file) {
    console.log("within if statement fired");
    reader.readAsDataURL(file);
    }
    else {
    console.log('else fired uploadFile');
    }
    }; // uploadFile()