我试图让用户上传图片,然后将图片以base64编码存储在firebase中。我正在尝试使我的 Firebase 结构如下:
- |--饲料
- |----饲料项目
- |------用户名
- |--------史诗
- |---------姓名等
- |--------图片
- |---------图片1、图片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”