0

我有一个文件URI,我正在尝试将其转换为 dataURL,以便可以将其上传到 Firebase。

目前我得到了 的路径/var/mobile/Containers/Data/Application/69BCC8B8-D539-4BA3-AD6B-B3ECBD8DEDE9/Library/Caches/myvideo_17.mp4,但我需要将其转换为一种方式(BLOB、String 等),以便我可以将视频上传到 Firebase。

我一直在搞乱 Cordova File 插件,但我似乎无法输入正确的信息来让它输出文件 dataUrl ...

任何帮助将非常感激。

4

1 回答 1

2

所以在休息了几个星期之后,回到这个问题上,我发现了这个问题。

事实证明,我一直在使用的插件正在剥离字符串中非常重要file://的部分的fileURI(我以前没有使用过) 。所以我只剩下/var/mobile/Containers/Data/Application/69BCC8B8-D539-4BA3-AD6B-B3ECBD8DEDE9/Library/Caches/myvideo_17.mp4.

所以在修复字符串之后(就像你在使用 base64Url 时所做的那样)。我最终得到以下结果:

'file://' + fileURI;

总之,我的代码现在看起来像这样:

resolveFileSystemUrl(media){
 let fixed = 'file://' + media;
 this.file.resolveLocalFilesystemUrl(fixed)
 .then(result => {
   this.resolveFileEntry(result);
 }).catch(err => {console.error('Error resolving the file system url'); });
}


resolveFileEntry(res) {
 res.file((resFile) => {
  let reader = new FileReader();
  reader.readAsDataURL(resFile);
  reader.onloadend = (evt: any) => {
    // the base64 of the video is: evt.target.result
  }
 });
}
于 2018-09-06T22:44:12.413 回答