What is the location of the files stored using the cordova-file-plugin?

Currently, I am in the process of developing an Excel application on a mobile device. Initially, I'm testing it out on Android, but the aim is to ensure compatibility with iOS devices as well.

To build this app, I referred to the official documentation and used the following code snippet:

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'
        fileEntry.createWriter(function (fileWriter) {

            fileWriter.onwriteend = function() {
                console.log("Successful file write...");
                fileEntry.file(function (file) {
                    var reader = new FileReader();

                    reader.onloadend = function() {
                        console.log("Successful file read: " + this.result);
                        //displayFileData(fileEntry.fullPath + ": " + this.result);
                    };

                    reader.readAsText(file);

                },);
            };

            fileWriter.onerror = function (e) {
                console.log("Failed file write: " + e.toString());
            };

            let dataObj = new Blob(['some file data'], { type: 'text/plain' });


            fileWriter.write(dataObj);
        });

    });

});

I attempted to modify the initial code block with the following lines, however, I encountered the same outcome:

window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (fs) {
    console.log('file system open: ' + fs.name);
    fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) { ...

The console output from my attempts was as follows:

file system open: persistent    
fileEntry is file?true    
Successful file write...    
Successful file read: some file data

Although the file appears to be successfully created and readable, no prompt or indication is provided. Upon navigating to my files at Android/data/com.myapp.app/files, I couldn't locate any file present there.

Answer №1

It appears that the files were successfully being saved, although they weren't visible to me. However, I was able to access them through the cordova-file-plugin.

I made a change to the destination folder:

let ruta = cordova.file.externalRootDirectory
let directoryRoute = "myApp";
            window.resolveLocalFileSystemURL(ruta, function (fs) {
                fs.getDirectory(directoryRoute, { create: true }, function (fs2) {
                    fs2.getFile(fileName, { create: true, exclusive: false }
, function (fileEntry) { ...

By using cordova.file.externalRootDirectory, I am creating a folder to store my app documents if it doesn't already exist. This method works with Android, but there may be variations for iOS.

I plan to provide an update on this answer in a few days once I have tested it with iOS. Hopefully, this information will be helpful to others.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Every time Grunt detects newer files, it automatically triggers the imagemin:dynamic task

I am working with a Gruntfile that looks like this: grunt.initConfig({ imagemin: { dynamic: { files: [ src: ['lib/public/img/*.{png,jpg,jpeg,gif}'], dst: 'build/public/img/', expand: true, fl ...

Transfer a variable from javascript/jquery to a PHP script within the same page

Possible Duplicate: How to transfer JavaScript variables to PHP without using a form? What is the best way to move a JavaScript variable to a PHP script without the need for form submission? Is this even achievable? Ajax seems to be a viable solutio ...

Experiencing difficulties while accessing the Android app

I created a basic Android application using Eclipse to establish a connection between the login and register data entry and the local server (utilizing both xampp and wamp) via a JSON web service. Initially, the application functioned correctly but it has ...

Troubleshooting the net::ERR_ABORTED 404 (Not Found) error while utilizing next/link to call an API route in NextJS

While developing an api route for downloading a CSV file, I encountered an error when using Next Link. Unfortunately, switching to another method is not an option as it would cause my application to fail to build. The component in question is straightforwa ...

Retrieving SQL information with PHP and transmitting an Array to JavaScript

Currently, I am faced with the task of parsing the SQL data that I retrieved with PHP into a JavaScript file. The challenge lies in storing the PHP array into JavaScript as I have a graph that relies on a JavaScript array to populate the data. At the mom ...

What is the best way to address cookie issues while working on a full stack application that utilizes Vue and Express.js?

Developing a full stack application requires me to use Vue on port 5173 and Express on port 3000. One issue I face is the inability to store credentials in the frontend for backend communication during development. This challenge can be addressed by servin ...

The React application is experiencing difficulty selecting CSS files through the code

I've encountered an issue with my React app where the button.css file is not rendering properly even though I've kept both the buttn.css and button.js in the same folder. Button.css .Button { background-color: transparent; border: none; ...

What is the best way to remove double quotes surrounding "name" and "count" when displayed in the JavaScript console output?

I am struggling to transform the input: ["apple", "banana", "carrot", "durian", "eggplant", "apple", "carrot"] into the desired output: [{ name: "Apple", count: 2 }, { name: ...

Streamline uploading files with AngularJS using Selenium

I am utilizing Powershell to operate .NET Selenium with a FirefoxDriver in order to automate certain tasks. One of these tasks involves file uploads, and the website I am working with appears to have been built using AngularJS. After some experimentation, ...

Javascript functions function properly only if they contain the 'alert()' command

My aim is to utilize Ajax (Javascript + php) for checking user name availability when a user moves focus to another form field. The strange part is that my functions only work when I include some alert(), without them, the functions fail to operate. Anoth ...

Error: Unable to access 'price' property of undefined - Next.js version 14.0.1

I'm encountering an issue with Next.js where my code is not working as expected. Interestingly, the same code works perfectly fine in other templates. let subTotal = 0 if (selectedProducts?.length) { for (let id of selectedProducts) { ...

AngularJS restricts inputs to be read-only

I'm facing an issue with readonly inputs in AngularJS. I have a select element that changes the values of readonly inputs through a script. However, when I attempt to display these values using ng-model in a table as {{ng-model}}, they don't appe ...

In Chrome, the $http GET request fails to send the JSESSIONID, but it functions properly on Firefox with AngularJS

Here is the code snippet I am working with: $http({ 'method': 'GET', 'url': 'http://www.example.com', 'withCredentials': true, headers: { 'Content-type': &apo ...

Step-by-step guide to uploading files using cucumber-js

Is there a way to write a script that can successfully fill out a form and upload a file using cucumber-js, selenium, and protractor? I am encountering an issue where there is no xpath/id available to click on when trying to upload a file. How have you d ...

Monitor Changes with Grunt: Be Prepared for Some Waiting!

My Grunt watch task is experiencing significant delays between detecting a file change and starting to work. Output similar to the following is frequently seen: >> File "src/static/app/brandManager/addChannel.html" changed. Running "html2js:main" ...

An argument was received with the --sdk flag, however, this particular argument is no longer

When using Buildozer to create an App from my python/kivy file, I encountered an error after running the following command line: buildozer android debug deploy run The error message is as follows: WARNING: Received a --sdk argument, but this argument is ...

Using pure JavaScript, you can apply a CSS property to hide an element by setting

Is there a way to hide a <section> element in HTML using JavaScript while highlighting the text or showing it in a different way? This is the solution I have tried: document.addEventListener('click', function(){ var selected = windo ...

What is the process for adjusting the width of an element using JavaScript?

I have a unique bar with one half red and the other green. I am trying to subtract 1vw from the width of the red section. Unfortunately, using style.width is not yielding the desired result. See below for the code snippet I am currently using: //FIGHT do ...

What is the best way to incorporate CSS into JavaScript code?

Here is the code I am working with: <script type = "text/javascript"> function pic1() { document.getElementById("img").src = "../images/images/1.png"; } function pic2() { document.getEl ...

Adding a distinct key and its corresponding value to an array in Vue for a unique

I am attempting to add key-value pairs into an array while ensuring their uniqueness. Currently, I am trying the following approach: for (const [key, value] of Object.entries(check)) { console.log(`${key}: ${value}`); this.inputFields. ...