Where is the location of file created by Cordova File Plugin?

Reading/wiring files in Cordova is painful. I wrote a script that uses promises to make this easier.

Add cordova-file-storage.js to your project, then do the following:

// the object you want to save
var objectToSave = { firstName: 'John', lastName: 'Doherty' };

// the filename and extension you want to use
var filename = 'whatever.txt';

// the data to write (convert JSON object to a string)
var data = JSON.stringify(objectToSave);

// call write with params, .then executes with the filePath once complete
fileStorage.write(filename, data).then(function(filePath) {
     console.log(filePath);
})
.catch(function(err) {
     // this executes if something went wrong
     console.warn(err);
});

It uses external storage by default. To use sandboxed storage inaccessible to the user add true as the last param.


Why I can't find the file on my device?

The file is created successfully but I can't find that on my device because the dataDirectory path which I indicates to create the file, is a private path and my device file manager doesn't have access to it (base on this table). Actually dataDirectory is an Internal Storage option.

Internal Storage: Store private data on the device memory.

You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.(reference)

How to create a public file?

So, to create a file on my device that I can access it with the file manager, I have to use one of public path options like:externalDataDirectory. Before, I was thinking it is for storing files on an external SD Card that I had not on my phone, so I didn't test it. But testing it today, it creates the file on my internal device storage in Android/data/<app-id>/files path which is public and I can access it with device file manager.

Actually the term internal and external was misleading for me while external storage can be a removable storage media (such as an SD card) or an internal (non-removable) storage(reference).