I can't convert the image to Base64 on iOS




I have a problem when I try to convert an image to Base64 from two different plugins. I don’t have this problem on Android, just iOS.
I’m trying to figure out if there’s a problem with Nativescript or a problem with the two plugins.
I use nativescript-camera and nativescript-imagepicker like that :


import * as camera from "nativescript-camera";
let options = { width: 900, height: 900, keepAspectRatio: true, saveToGallery: false};
      .then(function (imageAsset) {
            let source = new imageSourceModule.ImageSource();
                  .then( imageSource => {
                         console.log(imageSource.toBase64String("jpg",80)); // NULL

Image Picker

import * as imagepicker from "nativescript-imagepicker";
const context = imagepicker.create({ mode: "single" });
       .then(function() {
             return context.present();
        .then(function(selection) {
              selection.forEach(function (selected_item) {
                                .then(function (imageSource) {
                                      console.log(imageSource.toBase64String("jpg",80)); // NULL

My configuration

"nativescript-cli": "3.1.3",
"tns-core-modules" : "3.1.1",
"tns-android" : "3.2.0",
"tns-ios" : "3.2.0"


"@angular/*" : "4.1.3"
"nativescript-camera": "3.0.2",
"nativescript-imagepicker": "3.0.6",
"typescript": "2.4.2"




I’ve never used the quality parameter, but that code looks fine. Do you receive an error?


Hi @mast3rd3mon
I have no error or warnings.


I tried your code and I was surprised to see that it returning a string. The problem is that string is not a Base64 string, at least it’s not complete.
I mean, I tried on both OS and

  • Android returns a big string
  • iOS returns this :

I also tried to convert these strings to image via online converter Base64 Converter. It converted the Android string into proper image but the iOS string not.


That looks odd, possibly an ios bug or an error in your code maybe? It works fine on mine.

Can you try the following code in place of your takePicture method?

    width: 100,
    height: 150,
    keepAspectRatio: true,
    saveToGallery: false
}).then(imageAsset => {
        .then(res => {
            var imageCode = myImage.toBase64String("jpeg");


Hi @mast3rd3mon

Sorry for delay.
The issue was solved by changing the jpg to jpeg. I still don’t know why but this change solved my problem.
It works perfectly in Android & iOS.

Thanks for your help.