Search code examples
javascripttypescriptcordovaionic-frameworkcordova-plugins

Ionic 5 Native File plugin not writing files to dataDirectory


I'm trying to read and write files on the user's device. I'm using the Ionic File plugin, but whenever I try to create or write files, it gives no error, but does not create them.

The code that writes the files is a simple function only executing one line:

file.writeFile(file.dataDirectory + folderName, fileName, data, { replace: true });

Again, this code gives no errors, But when I navigate over to the folder on my phone Android/my.app.id/files/, the folder is empty.

I've tried changing my config.xml file as suggested by other forum posts by adding:

<allow-navigation href="*" />
<allow-navigation href="http://*/*" />
<allow-navigation href="file://*/*" />
<allow-intent href="*" />

I've also tried using the other directory options in the plugin, but am met with ENCODING_ERR.

How do I fix this?


Solution

  • So I've found the solution. I just set the directory to externalDataDirectory instead of dataDirectory.