Previously I could add the path of an image after converting it to an Base64
Input to later be displayed in a DIV , but after a while when trying to carry out the process now it does not allow me to carry out said action and the following message appears:
Before it worked on any computer, but now I don't know what could be causing the error. Here is the code:
angular.module('perfilEstudiante', ['ionic', 'ngCordova'])
.controller('mostrarPerfilEstu', mostrarPerfilEstu)
.directive('pickFile', pickFile)
.factory('obtenerPerfilEstu', obtenerPerfilEstu);
mostrarPerfilEstu.$inject = ['$scope', 'obtenerPerfilEstu'];
function mostrarPerfilEstu($scope, obtenerPerfilEstu, $element) {
var Perfil, Mes, Periodo_Estu, input, button, evtHandler, dataImage;
dataImage = localStorage.getItem("imgData");
if (dataImage === null) {
$scope.dataImage = "img/profile_icon.png";
} else {
$scope.dataImage = "data:image/png;base64," + dataImage;
}
$scope.loadImage = function (file) {
if (file.type.indexOf('image') < 0) {
$scope.res = "Tipo inválido";
$scope.$apply();
return;
}
var fReader = new FileReader();
fReader.onload = function () {
var data = fReader.result;
$scope.dataImage = data;
$scope.res = "";
$scope.$apply();
localStorage.setItem("imgData", data.replace(/^data:image\/(png|jpe?g);base64,/, ""));
};
fReader.readAsDataURL(file);
};
};
function pickFile() {
return {
restrict: 'EA',
scope: {
onselected: "&"
},
template: '<button class="button button-icon icon ion-plus-round pull-right">' +
'<input type="file" style="display: none !important">' +
'</button>',
link: function ($scope, $element) {
var input = $element.find('input');
var button = $element.find('button');
var evtHandler = function () {
input[0].click();
};
button.on('click', evtHandler)
input.on('change', function () {
var file = input[0].files[0];
$scope.onselected({
file: file
});
});
}
};
};
My phone has Android version 4.2.2
I was able to solve the problem using the plugin
$cordovaCamera
, Plugin LinkHTML
js