title: Passing base64 string to object's attribute in AngularJS
body: <p>I'm trying to upload an image via an input field, tie the base64 of the image to a variable, then add that variable to the attribute of an object so I can store it in my Firebase db. </p>
  
  <p>Input form &amp; field for object: </p>
  
  <pre><code>      &lt;div class="row modalDetail"&gt;
                &lt;h3&gt;New Episode&lt;/h3&gt;
                &lt;table class=""&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td class="labelField"&gt;Name&lt;/td&gt;
                      &lt;td&gt;&lt;input type='text' ng-model='episode.name'&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                      &lt;td class="labelField"&gt;Title&lt;/td&gt;
                      &lt;td&gt;&lt;input type='text' ng-model='episode.title'&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                      &lt;td class="labelField"&gt;Description&lt;/td&gt;
                      &lt;td&gt;&lt;input type='text' ng-model='episode.shortDescription'&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                      &lt;td class="labelField"&gt;Time&lt;/td&gt;
                      &lt;td&gt;&lt;input type='text' ng-model='episode.time'&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
                &lt;img src="../images/placeholder.png" id="pano"&gt;
  
                &lt;!-- START Image File Upload --&gt;        
                  &lt;td class="labelField"&gt;Image&lt;/td&gt;
                  &lt;span class="btn btn-default btn-file"&gt;
                    &lt;input type="file" accept="image/*" capture="camera" id="file-upload"&gt;
                  &lt;/span&gt;
                  &lt;div id="spin"&gt;&lt;/div&gt;
  
                &lt;div class='btn btn-warning' ng-click='createEpisode()'&gt; Create an Episode&lt;/div&gt;
        &lt;/div&gt;
  </code></pre>
  
  <p>The service for uploading to Firebase: </p>
  
  <pre><code>'use strict';
  
  app.service('Uploader', ['$firebase', 'FIREBASE_TEST_URL', function($firebase, FIREBASE_TEST_URL) {
  
      var ref = new Firebase(FIREBASE_TEST_URL);
  
      var episodes = $firebase(ref);
  
      return {
          all: episodes,
          create: function(episode) {
              location.reload();
              //Add to firebase db
              return episodes.$add(episode);
          },
          delete: function(episodeId) { 
              location.reload();
              return episodes.$remove(episodeId);
          },
          update: function(episode) {
              location.reload();
              return episodes.$save(episode);
          }
      };
  }]);
  </code></pre>
  
  <p>Controller that has the file handling for the image, etc.: </p>
  
  <pre><code>'use strict';
  
  app.controller('UploadCtrl', ['$scope', 'Uploader', function ($scope, Uploader) {
  
  $scope.episodes = Uploader.all;
  
  $scope.createEpisode = function(){
      Uploader.create($scope.episode).then(function(data){
          $scope.episode.name = '';
          $scope.episode.title = '';
          $scope.episode.description = '';
          $scope.episode.time = '';
          $scope.episode.img1 = $scope.episodeImgData;
      });
  };
  
  $scope.deleteEpisode = function(episodeId){
      bootbox.confirm('Are you sure you want to delete this episode?', function(result) {
          if (result === true) { 
              Uploader.delete(episodeId).then(function(data){
                  console.log('Episode successfully deleted!');
              });
          }
      });
  };
  
  $scope.updateEpisode = function(episode) {
      Uploader.update($scope.episode).then(function(data) {
          console.log(episode);
          console.log('Episode successfully updated.');
      });
  };
  
  $scope.selectEpisode = function(object) {
      $scope.selectedEpisode = object;
      setTimeout(function(){ $scope.$apply($scope.selectedEpisode = object); });
  };
  
  // ********************************************************************************** //
  // START Image Upload: https://github.com/firebase/firepano/blob/gh-pages/firepano.js //
  // REQUIRED: app/scripts/js/crypto.js in index.js
  var spinner = new Spinner({color: '#ddd'});
  $scope.episodeImgData = '../images/defaultplaceholder.png';
  
  function handleFileSelectAdd(evt) {
    var f = evt.target.files[0];
    var reader = new FileReader();
    reader.onload = (function(theFile) {
      return function(e) {
          var filePayload = e.target.result;
          var hash = CryptoJS.SHA256(Math.random() + CryptoJS.SHA256(filePayload));
  
          $scope.episodeImgData = e.target.result; 
  
          document.getElementById('pano').src = $scope.episodeImgData; 
          console.log($scope.episodeImgData);
      };
    })(f);
    reader.readAsDataURL(f);
  }
  
  function handleFileSelectEdit(evt) {
    var f = evt.target.files[0];
    var reader = new FileReader();
    reader.onload = (function(theFile) {
      return function(e) {
          var filePayload = e.target.result;
          var hash = CryptoJS.SHA256(Math.random() + CryptoJS.SHA256(filePayload));
  
          $scpope.episodeImgData = e.target.result; 
  
          document.getElementById('pano2').src = $scope.episodeImgData; 
          $scope.selectedEpisode.img1 = $scope.episodeImgData;
          console.log($scope.episodeImgData);
      };
    })(f);
    reader.readAsDataURL(f);
  }
  
  $(function() {
      $('#spin').append(spinner);
      document.getElementById('file-upload').addEventListener('change', handleFileSelectAdd, false);  
      document.getElementById('file-upload2').addEventListener('change', handleFileSelectEdit, false); 
  
  });
  // END Image Upload: https://github.com/firebase/firepano/blob/gh-pages/firepano.js //
  // ******************************************************************************** //
  }]);
  </code></pre>
  
  <p>All the attributes in the form save to the DB except img1. When the update button is clicked, I thought I could just pass in episodeImgData to the object (img1 variable) to save, but it doesn't save anything at all (just the form variables tied to episode.name, etc.). What's the best way to do this? I'm using parts of the FirePano example (<a href="https://github.com/firebase/firepano/blob/gh-pages/firepano.js" rel="nofollow">https://github.com/firebase/firepano/blob/gh-pages/firepano.js</a>) for the image handling. </p>