Does anyone have complete examples about how to use the Cordova Native File Plugin in a Ionic 2/Angular 2 project?
I installed this plugin but the documentation don't seems to make much sense to me due the fact it is fragmented and lacks of a complete example, including all needed imports.
For example, the following example don't shows where objects like LocalFileSystem or window came from.
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
console.log('file system open: ' + fs.name);
fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) {
console.log("fileEntry is file?" + fileEntry.isFile.toString());
// fileEntry.name == 'someFile.txt'
// fileEntry.fullPath == '/someFile.txt'
writeFile(fileEntry, null);
}, onErrorCreateFile);
}, onErrorLoadFs);
For example, I need to crate a property file. First I need to check if a file exists on app sandbox storage area, if don't exists I must create it. Then I must open the file write data and save it . How could I do that?
Here is an example using IonicNative for an app I am working on where I want to send an email with a csv file attachment.
This was tested with ionic 3.7.0 on IOS.
Ionic 2 comes with a Cordova file plugin wrapper: http://ionicframework.com/docs/v2/native/file/.
The necessary file system paths (e.g.
cordova.file.applicationDirectory
) you can find here at the documentation of the original plugin: https://github.com/apache/cordova-plugin-file#where-to-store-files. Note that not all platforms support the same storage paths.I even managed to build a file browser with it. Use it like so: