Plugin Base64 doesn't work on ionic 3

I'm working on Ionic 3, I'm geting the Url for the Image's user profile, I saving the file on a directory and save the path on the BD.

I need to convert the file to base64 and then sanitize but it show me in console the next message plugin_not_installed. I'm going crazy, I need their help

convertTobase64(){
     this.base64Image = 'C:\\Users\\Antonio\\Source\\Workspaces\\Ringer Tour\\RT.Api\\Data\\Tourist\\1\\image5204.jpg';

     this.base64.encodeFile(this.base64Image).then((base64File: string) => {
         this.base64Img = this.sanitizer.bypassSecurityTrustUrl(base64File);
    }, (err) => {
        console.log(err);
    });
}

Upvotes: 0

Views: 2741

Answers (2)

Jacob Nelson
Jacob Nelson

Reputation: 2466

You may use ionicframeworks File plugin. The method readAsDataURL will help to read file from given location and return data as a base64 encoded data url.

Upvotes: 1

Shreyas Pednekar
Shreyas Pednekar

Reputation: 1305

In JavaScript there are two functions respectively for decoding and encoding base64 strings:

1) atob() 2) btoa()

The atob() function decodes a string of data which has been encoded using base-64 encoding. Conversely, the btoa() function creates a base-64 encoded ASCII string from a "string" of binary data.

convertTobase64(){
    this.base64Image = 'C:\\Users\\Antonio\\Source\\Workspaces\\Ringer Tour\\RT.Api\\Data\\Tourist\\1\\image5204.jpg';

    var str: string;
    str = btoa(this.base64Image);     
}

Try this, I did this in my project to convert password in base64 string. You don't need to install any plugins for this.

Upvotes: 0

Related Questions