Ionic 4 + vue + capacitor. Filesystem writeFile. Base64 file decode error

Hi there!
First of all thx for reading this.

So I have this piece of code where I’m trying to save a pdf file from my API, which is encoded in base 64

downloadFile() {
      let fileTo = null;
      this.getProjectPd.project.files.forEach(file => {
        if ( == this.getProjectPd.idDocument) fileTo = file;
      let link = document.createElement("a");
      link.href = fileTo.file; =; = "_blank";;

      //Everything is written above not really important, it's related to the browser version
      // I have issues for the code below

      console.log( atob(fileTo.file.substr(28)) )
      try {
          path: `test1/${}`,
          data: atob(fileTo.file.substr(28)),
          directory: FilesystemDirectory.Documents,
          encoding: FilesystemEncoding.UTF8
      } catch (e) {
        console.error("Unable to write file", e);

so here is my attempt to encode file and save it

data: atob(fileTo.file.substr(28)),

this is result

and this what I get in the console

P.S the question is no longer relevant. Just need to delete encoding: FilesystemEncoding.UTF8 And pass to data: base64 string