【问题标题】:Translating Ionic video fileURI to dataURL, for Firebase upload将 Ionic 视频 fileURI 转换为 dataURL,用于 Firebase 上传
【发布时间】:2019-01-22 02:31:21
【问题描述】:

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

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

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

任何帮助将不胜感激。

【问题讨论】:

    标签: firebase ionic3 file-uri


    【解决方案1】:

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

    原来我一直在使用的插件正在剥离字符串中 VERY 重要的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
      }
     });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-13
      • 1970-01-01
      • 2020-01-23
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 2020-12-19
      相关资源
      最近更新 更多