D
D
Dmitry Chuprina2016-02-24 17:11:31
JavaScript
Dmitry Chuprina, 2016-02-24 17:11:31

Need to figure out how to create a cordova/phonegap file?

I can’t understand why there is no file in the file system after its creation, I reviewed a bunch of examples, and re-read the dock 10 times, but nothing.
When the function is executed, everything goes smoothly,
every step was debugged, but there is no file in the file system.
What am I missing, what am I doing wrong, please?
I am attaching the code:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {

                //console.log(fileSystem.name);
                //console.log(fileSystem.root.name);
                //console.log(fileSystem.root.fullPath);

                fileSystem.root.getFile("test.txt", {create: true}, function(entry) {
                    var fileEntry = entry;
                    console.log(entry);
                    entry.createWriter(function(writer) {
                        writer.onwrite = function(evt) {
                            console.log("some sample text");
                        };
                        console.log("writing to file");
                        writer.write("some sample text");

                    }, function(error) {
                        console.log(error);
                    });

                }, function(error){
                    console.log(error);
                });
            },
            function(event){
                console.log( evt.target.error.code );
            });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fr33zy, 2016-03-03
@fr33zy

Those. you have already installed the plugin.
Try opening the directory before opening the file:

window.resolveLocalFileSystemURL(
  cordova.file.dataDirectory,
  function(dirResolved) { /* getFile и т.д. */ },
  function(err) { /* обработка ошибок */}
);

And work with the file relative to this directory.
Other possible directories are on the plugin's github .
You may also need to change config.xml, see Android/iOS/… Quirks at the same link.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question