Problem: I am facing an issue with storing a picture in base 64 format. The window.plugins.Base64.encodeFile method is not functioning as expected.
I have successfully installed the Cordova Plugin locally and the $cordovaImagePicker is working fine. However, after fetching the image from the phone, it only stores the local image path in $scope.collected.selectedImage instead of converting it to base 64 format.
Any assistance on this matter would be greatly appreciated!
'use strict';
angular.module('copula')
.controller('ItemsCtrl', function($scope, $state, Auth, Item, $firebaseObject, $cordovaImagePicker, $ionicPlatform) {
var ref = new Firebase('https://copula.firebaseio.com/users');
var authData = Auth.$getAuth();
var itemsObject = $firebaseObject(ref.child(authData.uid + '/items'));
itemsObject.$loaded().then(function() {
$scope.items = itemsObject;
});
$scope.collection = {
selectedImage: ''
};
$scope.item = {};
$ionicPlatform.ready(function() {
$scope.getImageSaveContact = function() {
// Image picker will load images according to these settings
var options = {
maximumImagesCount: 1, // Max number of selected images, I'm using only one for this example
width: 800,
height: 800,
quality: 80 // Higher is better
};
$cordovaImagePicker.getPictures(options).then(function (results) {
$scope.collection.selectedImage = results[0]; // We loading only one image so we can use it like this
window.plugins.Base64.encodeFile($scope.collection.selectedImage, function(base64){ // Encode URI to Base64 needed for contacts plugin
console.log("before encoding");
$scope.collection.selectedImage = base64;
console.log(base64);
});
console.log($scope.collection.selectedImage);
}, function(error) {
console.log('Error: ' + JSON.stringify(error)); // In case of error
});
};
});
$scope.$on('$ionicView.beforeEnter', function (event, viewData) {
viewData.enableBack = true;
});
$scope.submitItem = function() {
ref.child(authData.uid).child('items').push(Item.pushAttrs($scope.item));
$scope.item = {};
$state.go('main.home');
};
});