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
    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 =",", 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.

        function (err) {
    }, function (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);