Cordova File Plugin giving Security error on using readAsDataUrl

I am using FileChooser to choose a file from my internal storage of my phone and File plugin to convert it into base64 but this.file.readAsDataUrl is giving error “FileError{code:2, Message:SECURITY_ERR}

I have all required permissions still the problem persists below is my code

let base=this
  if(this.platform.is('android')){
    this.fileChooser.open()
    .then(uri => {

      var array = uri.split("/");

      var path=uri.substring(0, uri.lastIndexOf("/") + 1);

      console.log("path"+path)
      base.file.readAsDataURL(path, uri).then(dataText=>{
        console.log(dataText)
        var data = dataText;

      },(error)=>{
      console.log(error)
      })
    //console.log(uri)

    })
    .catch(e => console.log(e));
  }

I am using Ionic 3, Angular4, Typescript, Firebase

1 Like

Hey. I’m having the exact same issue. Have you been able to find a solution?

If u are uploading files such as pdf/doc/xlsx etc… dont use file plugin , instead use filepath plugin to resolve native uri.

@kkhurana696 Can you provide a example how to use filepath plugin