Does anyone have complete examples about how to use the Cordova 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, this example don't show where come from objects like LocalFileSystem or window.
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);
Hello! Thanks for opening an issue with us! As this seems like more of a support question i will urge that you ask this question on our forum (forum.ionicframework.com). Also, be sure to check out Ionic Native to see out Angular 2, promise wrapped and typed version of the file plugin. Thanks for using Ionic!
Thanks for reply!
I posted a question in the forum.
I'm using the Ionic Native version, but its documentation don't say too much.
@Natanael1234 we are currently reviewing and improving the Ionic Native docs. Look for updates to them coming very soon!
Any movement on this? I'm not finding complete examples that make use of TS / Angular 2 / Ionic 2 anywhere in the documentation. The cordova examples also do not work in the ionic 2 framework...would be really awesome to have a simple example to start with. The current documentation leaves you with a native call that doesn't fire.
Something like this with TS / Angular 2 / Ionic 2
import {Component} from '@angular/core';
import {File} from 'ionic-native';
...
File.listDir(cordova.file.applicationDirectory, 'mySubFolder/mySubSubFolder').then(
(files) => {
// do something
}
).catch(
(err) => {
// do something
}
);
So the biggest issue is uri handling between the different file plugins. File picker returns an unusable path for file opener. It's not clear which plugin needs a path, a URI, or something else. Additionally, there are no bindings that I've seen to the externalStorageDirectory method in Java. I haven't looked at this in a while now, but this was the problem as far as I can recall. Looking at the ionic2 documentation there doesn't seem to be a change in regards to those plugins.
I thought this documentation was helpful:
https://github.com/apache/cordova-plugin-file#where-to-store-files
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Most helpful comment
Any movement on this? I'm not finding complete examples that make use of TS / Angular 2 / Ionic 2 anywhere in the documentation. The cordova examples also do not work in the ionic 2 framework...would be really awesome to have a simple example to start with. The current documentation leaves you with a native call that doesn't fire.