Select gallery image and send by post?

Asked

Viewed 595 times

1

I am creating a register of new users and in this register the user must choose his profile image(required). I can return the image of the gallery but the name of the image does not return, the return is this: localURL: "content://media/external/images/media/8018". I want the name of the image to be able to send to my webservice by post.

How do I do it ?

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();
    };    
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.