Skip to content

Instantly share code, notes, and snippets.

@GCoe
Forked from TheAnonymous/AngularFireUpload.js
Created February 28, 2016 16:52
Show Gist options
  • Select an option

  • Save GCoe/4dc15c113421f17a888d to your computer and use it in GitHub Desktop.

Select an option

Save GCoe/4dc15c113421f17a888d 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment