我正在尝试使用媒体捕获Ionic插件获取的音频录音,并将文件转换为base64字符串。 我已经附上了适用于Android的代码,但无法适用于IOS或Microsoft。
我注意到在我使用的base64转换插件中它说:
“获取任何图像的Base64编码的插件,可以为Android检索任何文件的Base64,但仅支持iOS图像。”
还有其他选项吗?我们也尝试了下面的文件插件,但是无法向其发送所需的确切文件路径(它要么返回空,要么返回错误)。我们还尝试了一种更本地的JavaScript解决方案,使用getUserMedia,但由于安全问题,这在IOS上也无法工作。
使用的插件:
- https://github.com/apache/cordova-plugin-file - https://github.com/apache/cordova-plugin-media-capture - https://github.com/hazemhagrass/phonegap-base64
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);
});
})
}
我注意到在我使用的base64转换插件中它说:
“获取任何图像的Base64编码的插件,可以为Android检索任何文件的Base64,但仅支持iOS图像。”
还有其他选项吗?我们也尝试了下面的文件插件,但是无法向其发送所需的确切文件路径(它要么返回空,要么返回错误)。我们还尝试了一种更本地的JavaScript解决方案,使用getUserMedia,但由于安全问题,这在IOS上也无法工作。
使用的插件:
- https://github.com/apache/cordova-plugin-file - https://github.com/apache/cordova-plugin-media-capture - https://github.com/hazemhagrass/phonegap-base64