Skip to content

Instantly share code, notes, and snippets.

@TheAnonymous
Created July 20, 2015 07:00
Show Gist options
  • Save TheAnonymous/1b8e1c3fd4d8239f47e2 to your computer and use it in GitHub Desktop.
Save TheAnonymous/1b8e1c3fd4d8239f47e2 to your computer and use it in GitHub Desktop.
Example code for Firebase with AngularJS to upload a image.
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();
<img id="profileImage" src="profileImage" style="max-width:200px; max-height:200px;">
<input type="file" accept="image/*" capture="camera" id="file-upload"> </div>
@JackMj
Copy link

JackMj commented Jun 18, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment