Search code examples
javascriptangulartypescriptionic3ionic-native

ENCODING_ERR Javascript Blob with Ionic file plugin


Can you tell me why this code is not working?

Note: file is native plugin

var blob = new Blob(["This is my blob content"], { type: "text/plain" });

    this.file.writeFile(this.file.dataDirectory, 'myletter.txt', blob, { replace: true })
      .then(() => {
        //code
      })
      .catch((err) => {
        console.error(err); //it comes to here
      });

It gives this exception:

FileError
code : 5
message : "ENCODING_ERR"
__proto__  : Object

Solution

  • I have found the issue here. That was due to this path this.file.dataDirectory.

    Solution: Use this instead this.file.externalApplicationStorageDirectory