In the File plugin, we should add a method for writing files.
It is kind of painful the way it is now. It was very easy in ngCordova. writeFile(path, file, data, replace)
I wrote this method to do it in a small sample app. It works but we need additional rigor around it.
writeFileInternal(directoryPath, fileName, fileContent){
return new Promise( (resolve, reject) => {
(<any>window).resolveLocalFileSystemURL(directoryPath, (fileSystem) => {
fileSystem.getFile(fileName, {create: true}, (fileEntry) => {
fileEntry.createWriter( (writer) => {
writer.onwriteend = function (evt) {
if (this.error) {
reject(new Error("Failed to write file"));
} else {
resolve(evt);
}
};
writer.write(fileContent);
}, (err) => {
console.log("ERROR: ", err);
reject(err);
});
});
});
});
Thanks,
Dan
Hey @danbucholtz
We have a new wrapper for the File plugin that is here in the dev branch: https://github.com/driftyco/ionic-native/blob/dev/src/plugins/file.ts
I should probably have time next week to finalize the plugin and merge it into master.
You rock @ihadeed !
Any updates about it? :)
Most helpful comment
Hey @danbucholtz
We have a new wrapper for the
Fileplugin that is here in the dev branch: https://github.com/driftyco/ionic-native/blob/dev/src/plugins/file.tsI should probably have time next week to finalize the plugin and merge it into master.