使用AngularFire将图像数组添加到Firebase

时间:2013-10-27 23:53:44

标签: image angularjs firebase angularfire

我正在尝试允许用户上传图片,然后将图片base64编码存储在firebase中。我正在努力使我的firebase结构如下:

  • | --Feed
  • | ---- Feed Item
  • | ------用户名
  • | ------史诗
  • |。---------名称等
  • | ------图像
  • | --------- image1,image 2等

但是,我无法获取firebase中的远程数据来镜像客户端中的本地数据。当我将图像数组打印到客户端的控制台时,它显示已上传的图像已添加到图像数组中......但这些图像从未进入firebase。我尝试过多种方式无济于事。我尝试使用隐式同步,显式同步和两者的混合。我可以为我的生活找出原因,为什么这不起作用,我变得非常沮丧。这是我的代码:

$scope.complete = function(epicName){


                for (var i = 0; i < $scope.activeEpics.length; i++){
                    if($scope.activeEpics[i].id === epicName){
                        var epicToAdd = $scope.activeEpics[i];

                    }
                } 


                var epicToAddToFeed = {epic: epicToAdd, username: $scope.currUser.username, userImage: $scope.currUser.image, props:0, images:['empty']};

                //connect to feed data
                var feedUrl = "https://myfirebaseurl.com/feed";
                $scope.feed = angularFireCollection(new Firebase(feedUrl));

                //add epic
                var added = $scope.feed.add(epicToAddToFeed).name();

                //connect to added epic in firebase
                var addedUrl = "https://myfirebaseurl.com/feed/" + added;
                var addedRef = new Firebase(addedUrl);
                angularFire(addedRef, $scope, 'added').then(function(){

                    // for each image uploaded, add image to the added epic's array of images
                    for (var i = 0, f; f = $scope.files[i]; i++) {
                        var reader = new FileReader();
                        reader.onload = (function(theFile) {
                            return function(e) {
                                var filePayload = e.target.result;
                                $scope.added.images.push(filePayload);
                            };
                        })(f);
                        reader.readAsDataURL(f);
                    } 
                });
            } 
编辑:想出来,必须连接到“https://myfirebaseurl.com/feed/”+添加+“/ images”

0 个答案:

没有答案