2

I have a service that handles "episodes": creating, deleting and updating them. It looks like this:

app.service('Episode', ['$firebase', 'FIREBASE_URL', function($firebase, FIREBASE_URL) {

    var ref = new Firebase(FIREBASE_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);
        }
    };
}]);

Inside my controller:

app.controller('AdminCtrl', ['$scope', 'Episode', function ($scope, Episode) {

$scope.episodes = Episode.all;

$scope.createEpisode = function(){
    Episode.create($scope.episode).then(function(data){
        $scope.episode.name = '';
        $scope.episode.title = '';
        $scope.episode.description = '';
        $scope.episode.time = '';
        $scope.episode.img = '';
    });
};

$scope.deleteEpisode = function(episodeId){
    if(confirm('Are you sure you want to delete this episode?') === true) {
        Episode.delete(episodeId).then(function(data){
        console.log('Episode successfully deleted!');
        });
    }
};

$scope.updateEpisode = function(episode) {
    Episode.update($scope.episode).then(function(data) {
        console.log('Episode successfully updated.');
    });
};

The only example of uploading images to Firebase from AngularJS I've seen online is this: https://github.com/firebase/firepano

How am I able to incorporate this into an object based addition/update instead of finding it's index/link?

albaba
  • 153
  • 4
  • 12
  • See http://stackoverflow.com/questions/13955813/how-can-i-view-and-store-images-in-firebase. It mostly refers to Firepano. That entire application is in this JavaScript file: http://firebase.github.io/firepano/firepano.js – Frank van Puffelen Aug 08 '14 at 20:11
  • As I stated in my question, I'm looking to pass an image as attribute to an object, instead of finding the index of an object and setting it with a link. Firebase recommends updating and saving whole objects like: https://www.firebase.com/docs/web/guide/saving-data.html#section-push, but their example (Firepano) uses indexes. – albaba Aug 08 '14 at 21:09
  • Unless I'm mistaken that is exactly what the `handleFileSelect` function in firepano.js does. It takes the file the user selected and calls `f.set` to set the value on a Firebase ref. – Frank van Puffelen Aug 09 '14 at 02:40
  • 1
    Frank's assessment here is right. I'd also add that you should store the images in a separate path from other meta data (this is real-time data and byte counts are your biggest enemy for speed). Additionally, Firebase does not recommend setting whole objects over specific keys. That's a use-case specific decision. – Kato Aug 11 '14 at 16:25

0 Answers0