插件 Base64 不适用于 ionic 3

Plugin Base64 doesn't work on ionic 3

我正在使用 Ionic 3,我正在为图像的用户配置文件获取 Url,我将文件保存在目录中并将路径保存在 BD 中。

我需要将文件转换为 base64,然后进行清理,但它会在控制台中显示下一条消息 plugin_not_installed。我要疯了,我需要他们的帮助

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);
    });
}

在JavaScript中有两个函数分别对base64字符串进行解码和编码:

1) atob() 2) btoa()

atob() 函数对使用 base-64 编码的数据字符串进行解码。相反,btoa() 函数从 "string" 二进制数据创建一个 base-64 编码的 ASCII 字符串。

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

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

试试这个,我在我的项目中这样做是为了将密码转换为 base64 字符串。 您不需要为此安装任何插件。

您可以使用 ionicframeworks File 插件。 readAsDataURL 方法将有助于从给定位置读取文件和 return 数据作为 base64 编码数据 url.