简体   繁体   English

插件Base64在ionic 3上不起作用

[英]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. 我正在使用Ionic 3,正在获取图像用户配置文件的Url,将文件保存在目录中,并将路径保存在BD上。

I need to convert the file to base64 and then sanitize but it show me in console the next message plugin_not_installed . 我需要将文件转换为base64,然后进行清理,但是它将在控制台中向我显示下一条消息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);
    });
}

You may use ionicframeworks File plugin. 您可以使用ionicframeworks 文件插件。 The method readAsDataURL will help to read file from given location and return data as a base64 encoded data url. readAsDataURL方法将帮助从给定位置读取文件,并将数据作为base64编码的数据url返回。

In JavaScript there are two functions respectively for decoding and encoding base64 strings: 在JavaScript中,有两个函数分别用于解码和编码base64字符串:

1) atob() 2) btoa() 1)atob()2)btoa()

The atob() function decodes a string of data which has been encoded using base-64 encoding. atob()函数对使用base-64编码方式编码的数据字符串进行解码。 Conversely, the btoa() function creates a base-64 encoded ASCII string from a "string" of binary data. 相反,btoa()函数从二进制数据的“字符串”创建以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);     
}

Try this, I did this in my project to convert password in base64 string. 试试这个,我在我的项目中这样做是为了将密码转换为base64字符串。 You don't need to install any plugins for this. 您不需要为此安装任何插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM