Created
July 20, 2015 07:00
-
-
Save TheAnonymous/1b8e1c3fd4d8239f47e2 to your computer and use it in GitHub Desktop.
Example code for Firebase with AngularJS to upload a image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var refImg = new Firebase("https://YOURURL.firebaseio.com/images/" + $rootScope.authData.uid); | |
var ImgObj = $firebaseObject(refImg); | |
function saveimage(e1) { | |
var filename = e1.target.files[0]; | |
var fr = new FileReader(); | |
fr.onload = function (res) { | |
$scope.image = res.target.result; | |
ImgObj.image = res.target.result; | |
ImgObj.$save().then(function (val) { | |
}, function (error) { | |
console.log("ERROR", error); | |
}) | |
}; | |
fr.readAsDataURL(filename); | |
} | |
document.getElementById("file-upload").addEventListener('change', saveimage, false); | |
this.loadimage = function () { | |
ImgObj.$loaded().then(function (obj) { | |
$scope.profileImage = obj.image; | |
console.log("loaded", $scope.profileImage); | |
document.getElementById("profileImage").src = obj.image; | |
}, function (error) { | |
console.log("ERROR", error); | |
}); | |
}; | |
this.loadimage(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img id="profileImage" src="profileImage" style="max-width:200px; max-height:200px;"> | |
<input type="file" accept="image/*" capture="camera" id="file-upload"> </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, i see you managed to do the profile page, im trying to achieve the same thing but the problem is that when i bind my $scope.displayName and $scope.id (authData.google) on my view it shows nothing no errors. how did you archieve this?