javascript - How to read valid base64 file in Android? (cordova) -


i need read pdf filesystem in android in order send server. cannot seem read valid data however.

i have tried readasdataurl appears fastest. value returned (after removing mime type) invalid base64.

      // read file filesystem   window.resolvelocalfilesystemurl(path,     function (fileentry) {       fileentry.file(function (file) {         var reader = new filereader();          reader.onloadend = function (evt) {            // test base64 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 execute 'atob' on 'window': string decoded not correctly encoded.         };          //reader.readastext(file);          reader.readasdataurl(file);       },         function (err) {           console.error(err);         });     }, function (err) {       console.error(err);     }); 

i have tried readastext , converted base64 myself, incredibly slow large pdf files , data when translated not valid.

why base64 readasdataurl not valid? have tried on multiple android devices (with , without crosswalk). using latest version of file plugin.

it known , reported issue of file plugin of cordova.

filereader readasdataurl have issues when base 64 encoding large files. process used following:

  • base64 encode each 256k chunk.
  • append base64 encoded chunk of 256k.
  • return result.

the result not valid base64 encoded string instead string composed of multiple valid base64 encoded string appended.

one workaround instead of decoding result split data in part of 256k chunk, decode each chunk individually , you'll able re-encode whole string.

regarding the issue, it's tagged affecting android 4.4.2 problem still exists in android 5 & 6. regarding resolution, it's still not assigned anyone.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -