-
-
Save GCoe/4dc15c113421f17a888d 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