Read file in base64?

I am having an issue reading valid base64 from a file on the file system in Android using the file cordova plugin.

Has anyone had an issue like this before and can help? The PDF files I am trying to read are not working when reversing the base64.

  // read the file from the filesystem
  window.resolveLocalFileSystemURL(path,
    function (fileEntry) {
      fileEntry.file(function (file) {
        var reader = new FileReader();

        reader.onloadend = function (evt) {

          // test base64 is valid
          var patt = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
          var b64 = evt.target.result.split(",", 2)[1];
          console.log("is valid base64? " + patt.test(b64)); // false!

          var bytes = atob(b64); // Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
        };

        //reader.readAsText(file); 
        reader.readAsDataURL(file);
      },
        function (err) {
          console.error(err);
        });
    }, function (err) {
      console.error(err);
    });

More information on Stack Overflow here.

it works fine for me . . .

file path will be your app package name

window[‘plugins’].Base64.encodeFile(‘filePath’, function(base64) {
console.log('file base64 encoding: ’ + base64);
});