Save URI image from contacts to base64 and load in another page


#1

Hi, I’m trying to save the profile photo of one of my contacts to a base64. I want to load this image on another screen. To load this I use nativescript-contacts which says that con.photo should return an ImageSource instance. When I print it I get this:

{
JS:   "photo_uri": "content://com.android.contacts/display_photo/1"
}

And when I log the base64 version I get nothing. Does anybody know what I’m doing wrong and how I could fix it? Thanks in advance!

ContactSelector.getContact().then(function (args) {
        if (args.response === "selected") {
            var con = args.data;

            //Store image
            if(con.photo != null){
                console.log("not null!");
                console.log(con.photo);
                console.log(con.photo["photo_uri"].toBase64String("png"));
            } else{
                console.log("null :(");
            }
        }

#2

That’s a content uri not a real file, you need a ImageSource for converting it into base64. ImageSource is usually created from bitmap or file. So you will have to find a way to convert your content uri into bitmap.


#3

How would I convert this uri into an ImageSource or load it in my xml?
I’m new to NativeScript and can’t find any (non depricated) code to do this.