Base64插件无法正常工作

Tej*_*s K 3 cordova ionic-framework cordova-plugins ionic2 ionic3

直到最近我开始遇到插件问题,该插件才能正常工作,该代码无法执行,也不会引发错误。我想从相机捕获图像并将base64字符串发送到服务器,这很容易,因为我可以直接获取base64捕获图像的图像,但是随后我使用了本地作物,该作物返回了URI图像的图像。因此,现在我必须获取base64此图片的,但是该Base64插件不再起作用。任何解决方法或帮助都非常感谢。我使用的代码:

this.base64.encodeFile(filePath).then((base64File: string) => {
    console.log(base64File);    // Won't execute
}, (err) => {
    console.log(err);  // Won't execute
});
Run Code Online (Sandbox Code Playgroud)

小智 5

我花了几个小时研究同一个错误。发生了这个插件刚刚停止工作的情况(它仍然是Beta版)。我对代码进行了一些更改,并用文件插件替换了Base64插件。

  1. 将文件插件添加到app.module.ts导入。
  2. 在组件/服务构造函数中导入和注入依赖项。

然后,如果您有文件路径:

// split file path to directory and file name
let fileName = filePath.split('/').pop();
let path = filePath.substring(0, filePath.lastIndexOf("/") + 1);

this.file.readAsDataURL(path, fileName)
.then(base64File => {
    console.log("here is encoded image ", base64File)
})
.catch(() => {
    console.log('Error reading file');
})
Run Code Online (Sandbox Code Playgroud)