Aaron Ullal
Aaron Ullal

Reputation: 5245

Nativescript imageSource.fromAsset getImageAsync error

I am trying to upload base64 encoded image picked from the device's gallery.

Basically I select the picture and set it as source of an ImageView. Later I upload whatever the src of the ImageView is.

I'm using nativescript-imagepicker for the selection of the image :

let context = imagePicker.create({
        mode : "single"
    });
    context.authorize()
        .then(()=>{ return context.present();})
        .then((selection)=>{
            selection.forEach((selected)=>{
                selected.getImage().then((value :ImageSource)=>{
                    imageView.src = value; //here I set the image as source
                })
            })
        });

Afterwards in the upload method I try to do the following : The fromAsset method is part of the Nativescript's ImageSource module.

fromAsset(imageView.src).then(
    (res) => {
    imageSource = res;
    photo.base64 = imageSource.toBase64String('jpg');
    ..
}).catch((error)=>{
    console.log(error); // here I get TypeError.asset.getImageAsync is not a function
})

When I use the above method with an image snapped directly from the camera everything goes smoothly, however if the image is selected from gallery I get the following error : TypeError.asset.getImageAsync is not a function

What am I doing wrong?

Upvotes: 1

Views: 2004

Answers (1)

Emmanuel Castro Soto
Emmanuel Castro Soto

Reputation: 26

I used the code in this link and is working perfect! I hope it works https://github.com/NativeScript/nativescript-imagepicker/issues/62

Upvotes: 1

Related Questions