Search code examples
cordovawindows-10-universalvisual-studio-cordovacordova-plugin-file

Reading file system Windows apache cordova app


I am using the cordova-file plugin to read a file I have stored in my app and load it for the user to view.

I have the following code:

function readFileName(identifier) {
        var ret = ""
        var directory = cordova.file.applicationDirectory + "www/presentations/files/";
        var fileName = identifier.getAttribute("data-link")
        window.resolveLocalFileSystemURL(directory, function (directoryEntry) {
            directoryEntry.getFile(fileName, { create: false }, function (fileEntry) {
                ret = fileEntry.nativeURL;
            }, ret = null);
        }, fail);
        return ret;
    }

directory resolves as ms-appx:///www/presentations/files/

The code works fine in Android, but in a Windows App, it returns an error code of 5 which according to the docs is ENCODING_ERR.

I'm assuming it's because the path to my file is incorrect, but the docs say that ApplicationStorage works on Windows 10 and haven't found anything to suggest that the www/presentations/files/ folder doesn't exist (It certainly exists in my deug folder).

I'm pretty stuck as to work out how to resolve. Even when I try to resolve the root directory like so:

 window.resolveLocalFileSystemURL(directory, function (directoryEntry) {
            var reader = directoryEntry.createReader();
            reader.readEntries(function success(entries) {
                var i;
                for (i = 0; i < entries.length; i++) {

                    console.log('En - ', entries[i].fileName);
                }
            }, fail);

I still get the same error. Any pointers would be greatly appreciated.

Edit:

I have looked at the following bug

https://github.com/Reon90/cordova-plugin-file/blob/a4df917e66d0c35cb3e11ca3257f54b8b7dd3eab/src/windows/FileProxy.js

I have applied the change to the file but am still getting the same error


Solution

  • I have looked at the following bug https://github.com/Reon90/cordova-plugin-file/blob/a4df917e66d0c35cb3e11ca3257f54b8b7dd3eab/src/windows/FileProxy.js I have applied the change to the file but am still getting the same error

    I made a demo and tried fixing it with the codes from this link. It didn't work at first. But after I removed the windows platform using Command cordova platform rm windows and run the application again. It works!

    Notes: For details about what has been made to fix the problem please refer to Changes made to FileProxy.js.