Convert image to base64 with IonicFramework

Is there any library that allows converting images to base64 with the Ionic framework ?

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

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

remarks:

  • I want to get the uploaded image both from the camera with the Cordova , as well as the image gallery of Android .
Author: Felipe Paetzold, 2016-11-08

1 answers

In this case you use a ngCordova plugin called camera but with some different attributes in which it is 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
    });
  }
 4
Author: Augusto Miguel Zeponi, 2016-11-10 17:51:27