Bug in Ionic Native File Plugin - {"code":5,"message":"ENCODING_ERR"}


#1

I’m running the following code with Ionic Native File Plugin:

  accessFile(path, fileName) {
    return this.file.readAsDataURL(path, fileName).then((result) => {
      return result;
    }).catch(err => console.log('readAsDataURL Error', JSON.stringify(err)));
  }

I’m getting this error:

readAsDataURL Error {“code”:5,“message”:“ENCODING_ERR”}

I’m using WKWebView and here’s my Ionic Info:

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0
cordova (Cordova CLI) : 7.1.0 
@ionic/app-scripts : 1.3.12
Cordova Platforms  : ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2
ios-deploy : 1.9.2 
Node       : v8.11.1
npm        : 5.6.0 
OS         : macOS High Sierra
Xcode      : Xcode 9.4.1 Build version 9F2000 

Working on iOS.

I’ve tried the Path with file:/// and without it, both ways still give the same error.

My Path looks like this:

file:///private/var/mobile/Containers/Data/Application/E9…D/tmp/

Any ideas?


#2

Not the solution, but about file://, if you use wkwebview you shouldn’t use file:// in the path, see documentation https://ionicframework.com/docs/wkwebview/ “Rewriting file://”

Then about the error, did you saw that post on stackoverflow https://stackoverflow.com/questions/45910519/ionic-3-native-file-code-5-message-encoding-err?


#3

Ionic transition docs are actually wrong, you do need file://. Here’s my answer:

By trial and error I got the answer. You need to get rid of the /private/ and keep file://, so that your path goes like file:///var/… I’m getting this path from Video Editor after transcoding and trimming the video, so this case maybe unique. Also to point out, according to Ionic guide for transfer from UIWebView to WKWebView file:// is no longer needed, which is clearly not the case here.


#4

Excellent! Weird but it works! :slight_smile: