I am creating a new user registry and in this register the user must choose his profile image (mandatory). I can return the gallery image but the image name does not return, the return is that: localURL: "content://media/external/images/media/8018"
. I want the image name to be able to send to my webservice by post.
How do I do this?
I'm trying like this.
template
<ion-view view-title="Cadastro" align-title="center">
<ion-nav-buttons side="left">
<button class="button button-clear ion-arrow-left-c" ng-click="goBack();">
</button>
</ion-nav-buttons>
<ion-content>
<form name="User">
<div>
<img ng-src="img/ionic.png" id="smallimage" width="150" heigth="150">
<input type="file" ng-model="User.imageFile" size="30" id="imageFile" required="true"/>
<button class="button button-stable" ng-click="selectImage();">Imagem</button>
</div>
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="Nome" ng-model="User.nome" required="true">
</label>
<br/>
<label class="item item-input">
<input type="email" placeholder="Email" ng-model="User.email" required="true">
</label>
<br/>
<label class="item item-input">
<input type="password" placeholder="Senha" ng-model="User.senha" ng-minlength="8" maxlength="8"
required="true">
</label>
<br/>
</div>
</form>
<button type="button" class="button button-block button-energized"
ng-disabled="User.$invalid" ng-click="addUsuarioApp(User);">Cadastrar</button>
</ion-content>
</ion-view>
factory camera
var app = angular.module('starter');
app.factory('CameraFactory', ['$q', function($q) {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: 0, // 0:Photo Library, 1=Camera, 2=Saved Photo Album
}
var onSuccess = function(imageData) {
window.resolveLocalFileSystemURI(imageData, function(fileEntry) {
fileEntry.file(function(filee) {
console.log(filee);
//exibe: localURL: "content://media/external/images/media/8018"
});
});
var image = document.getElementById('smallimage');
var imageFile = document.getElementById('imageFile');
image.src = imageData;
imageFile.value = imageData;
};
var onFail = function(e) {
console.log("onFail! " + e);
};
return {
getPicture: function() {
return navigator.camera.getPicture(onSuccess,onFail,options);
}
}
}]);
User controller
var app = angular.module("starter");
app.controller("UserCtrl", function($scope, CameraFactory){
$scope.selectImage = function() {
CameraFactory.getPicture();
};
}