Hello,
we use the createWriter function of 'cordova-plugin-file' to write a .txt log file.
The log procedure has been active for about a month and the app is recompiled every week to add new modifications.
Today, after a new recompile,the system returns the error listed below and it do not save the file.
I notice an AppBuilder Upgrade.
Have you made some changes on the plugin, or in cordova .js file ?
This is the error message:
Wrong type for parameter "path" of DirectoryEntry.getFile: Expected String, but got Undefined." at file: cordova.js (424)
And below the simple code we use to write ...
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile("debug.txt", {create: true, exclusive: false}, function(fileEntry) {
fileEntry.createWriter(function(writer) {
writer.seek(writer.length);
writer.write('some text'); // this instruction generate the reported error
...
Many Thanks
Best Regards
Nicola
8 Answers, 1 is accepted
Sorry,
the reported error is after a further processing.
The raw error arises in the fileWriter onerror procedure : Error Code = 6 : NO_MODIFICATION_ALLOWED_ERR
fileWriter.onerror = function(evt) {
console.log("[writer.onerror]"); // Error code = 6 : NO_MODIFICATION_ALLOWED_ERR
....
};
Sorry,
the reported error is after a further processing.
The raw error arises in the fileWriter onerror procedure : Error Code = 6 : NO_MODIFICATION_ALLOWED_ERR
fileWriter.onerror = function(evt) {
console.log("[writer.onerror]"); // Error code = 6 : NO_MODIFICATION_ALLOWED_ERR
....
};
Nicola
I tested also the sample-file Telerik project.
Inserting the missing onerror funtion (or debugging the plug-in write call), the error raises.
The first write operation generates the error but writes the file on system. Subsequent append operations overwrite the just written file.
Debugging the plug-in you can see that,in the case of error, the 'position' variable isn't increased then the writing always starts from position 0
Nicola
More info :
the error arises with only some Android devices and only with Cordova 4.1.1. I tested vers. 3.8 and 5.0 (experimental) and the writing is succesfull
Hi Nicola, Telerik team,
I'm having the exact same problem (after several investigations).
Please help !
the only 'real' solution I found is to use Cordova 3.8 or Cordova 5.0.
With the 4.1.1 version, on some phones (like Samsung S4) the procedure works well, on some others (like Samsung Tablet) the same procedure raises the over mentioned error.
I noticed that the error interfers with the subsequent writing operations (appending text on same file not changes the 'position' value on file).
The first one operation does not suffers of this error (the write position is 0 !!) so it seems to work without errors .
With the Telerik sample indeed the writing is performed once
"Funny". I really have the exact same issue.
I am performing lots of writings in a text file (like logs) and I couldn't find why sometimes it was written and sometimes not... It looks a bit aleatory (error raised but sometimes the seek was anyway performed and sometimes not).
And as you mentionned it was working well with some phones (Sony Xperia Z5 compact) and not with others (Samsung J5).
So I'm now testing it under 3.8. It works until now (at least without the error raised). Will see tonight if it is stable.
Let's see if Telerik has an explanation.
I tested this functionality invoking the createWriter function on the File sample (Cordova 4.1.1) and it seems to work fine in this particular setup. For your convenience, I attached the demo to this conversation.
Would you please verify how the sample works at your side and let me know the result. In case there is an issue with a different setup, would you please open a new support ticket and provide a demo app there so that we can investigate the exact case further?
The version of the default File core plugin is 2.0.0 and there are indeed some known issues with it related to the onerror and onwrite functions. Would you try to use the latest version of the plugin compatible with Cordova version 4.1.1 for Android - as to working with various plugins in AppBuilder, please refer to the documentation on Import Custom Plugins?
If you import plugin's latest version, then please note the core File plugin which is enabled in all build configurations by default should be disabled. You can choose which plugins to enable when you build with the debug and the release configurations as explained in the documentation on Configure the Core Plugins.
Regards,
Dimitrina
Telerik
Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.