小编teh*_*thi的帖子

如何使用 ionic Angular 项目插件将音频文件转换为 Base64

我正在尝试从媒体捕获离子插件中获取音频录音并将文件转换为 Base64 字符串。我已附加适用于 Android 的代码,但不适用于 IOS 或 Microsoft。

public captureAudio(name: string, notes: string): void {

    this.mediaCapture.captureAudio().then(res => {
        var filePath = res[0].fullPath;

        this.getBase64StringByFilePath(filePath)
            .then((res) => {
                var base64Only = res.slice(34);
                //do something with base64 string
            });
    });
}

public getBase64StringByFilePath(fileURL: string): Promise<string> {

    return new Promise((resolve, reject) => {
        this.base64.encodeFile(fileURL).then((base64File: string) => {
            resolve(base64File);
        }, (err) => {
            console.log(err);
        });
    })
}
Run Code Online (Sandbox Code Playgroud)

我注意到在我使用的 base64 转换插件中它指出:

“用于获取任何图像的 Base64 编码的插件,可以为 Android 的任何文件检索 Base64,但仅支持 iOS 图像”

还有其他选择吗?我们也研究了下面的文件插件,但无法向其发送所需的确切文件路径(它要么不返回任何内容,要么返回错误)。我们还尝试了使用 getUserMedia 的更原生的 JavaScript 解决方案,但由于安全原因,该解决方案在 IOS 上也不起作用。 …

plugins base64 ionic-framework angular

6
推荐指数
1
解决办法
2030
查看次数

标签 统计

angular ×1

base64 ×1

ionic-framework ×1

plugins ×1