Convert image to base64 with IonicFramework

6

Is there a library that allows you to convert images to base64 with the Ionic Framework ?

I tried using angular-base64-upload , it worked with angular, but in Ionic did not succeed.

If anyone knows a library would be very grateful, or even some native way of doing the conversion.

Remarks:

  • I want to get the loaded image of both the camera with the Cordova plugin and the Android gallery.
asked by anonymous 08.11.2016 / 13:57

1 answer

4

In this case you use a ngCordova plugin called camera but with some different attributes in it below.

$scope.abrirGaleria = function () {
    var options = {
      quality: 50,
      destinationType: Camera.DestinationType.DATA_URL,
      sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
      allowEdit: true,
      encodingType: Camera.EncodingType.JPEG,
      targetWidth: 100,
      targetHeight: 100,
      popoverOptions: CameraPopoverOptions,
      saveToPhotoAlbum: false
    };

    $cordovaCamera.getPicture(options).then(function(imageData) {
      var image = document.getElementById('myImage');
      image.src = "data:image/jpeg;base64," + imageData;
    }, function(err) {
      // error
    });
  }
    
10.11.2016 / 18:31