firebaseionic3file-uri

Translating Ionic video fileURI to dataURL, for Firebase upload


I have a fileURI that i am trying to convert into a dataURL so that I can upload it to Firebase.

Currently I get the path of /var/mobile/Containers/Data/Application/69BCC8B8-D539-4BA3-AD6B-B3ECBD8DEDE9/Library/Caches/myvideo_17.mp4, but I need this to be converted into a way (BLOB, String, etc...) so that I can upload the video to Firebase.

I have been messing around with the Cordova File plugin, but i cannot seem to input the correct information to get it to output the file dataUrl...

any help would be much appreciated.


Solution

  • So after taking a few weeks off, and coming back to this, I figured out the issue.

    Turns out that the plugin I have been using was stripping the fileURI (which I have not previously used), of the VERY important file:// part of the string. So I was left with /var/mobile/Containers/Data/Application/69BCC8B8-D539-4BA3-AD6B-B3ECBD8DEDE9/Library/Caches/myvideo_17.mp4.

    So after fixing the string (like you do when using base64Url's). I ended up with the following:

    'file://' + fileURI;

    Which all together, my code now looks like this:

    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
      }
     });
    }