Can anyone suggest an online source to obtain the CORRECT file system writing documentation.
I have tried all online examples and none work. In particular, I tried this github cordova-plugin-file documentation::
function requestFS()
{
confirm("requestfs begin");
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) {
confirm("in requestfs");
// console.log("fileEntry is file?" + fileEntry.isFile.toString());
// fileEntry.name == 'someFile.txt'
// fileEntry.fullPath == '/someFile.txt'
writeFile(fileEntry, null);
}, fail);
}, fail);
function writeMyFile(fileEntry, dataObj) {
confirm("writemyfile begin");
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function() {
// console.log("Successful file write...");
confirm("successful file write");
readFile(fileEntry);
};
fileWriter.onerror = function (e) {
// console.log("Failed file write: " + e.toString());
confirm("file write failed");
};
// If data object is not passed in,
// create a new Blob instead.
if (!dataObj) {
dataObj = new Blob(['some file data'], { type: 'text/plain' });
}
fileWriter.write(dataObj);
confirm("after fileWriter.write");
});
}
Which gets passed the request for file system and no other confirms are reached.
Plus, I also tried:
function myWrite()
{
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
confirm("after request filesystem");
setTimeout(function(){
nothing();
},500);
readme.txt += "123467890";
function gotFS(fileSystem) {
confirm("in gotFS");
var path = "readme.txt";
fileSystem.root.getFile(path, {create: true, exclusive: false}, gotFileEntry, fail);
confirm("end of gotFS");
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
confirm("gotfileentry");
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
confirm("write Success");
};
writer.write("some sample text");
}
}
which never reaches gotFS.
Any information will be helpful. thanks.