Convert Image to Base64 with Ionicframework

Asked

Viewed 476 times

6

Is there any library that can convert images to base64 with the Ionic Framework?

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

If anyone knows any library would be very grateful, or even some native way to make the conversion.

Remarks:

  • I want to get the image loaded both from the camera with the plugin Cordova, as well as the image gallery Android.

1 answer

4


In this case you use an ngCordova plugin called camera but with some different attributes in which this 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
    });
  }

Browser other questions tagged

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