FileSystem root.fullPath return undefined and root.getFile gives "processMessage failed error" in phonegap.js

2.8k views Asked by At

this is my first question here, so sorry if I'm writing bad my request. I'm creating a project with Sencha Touch 2.4.1 and PhoneGap (my main target is Android), using the command

sencha app build native

to package. To be short, I need to request the file system and then download some file (images). According to posts like this, I'm trying to use the "getFile()" function before start downloads, but even a simple code like this gives me troubles:

Ext.define("MyApp.utils.Globals", {
    singleton: true,
    alias: 'widget.globals',
    config: {
        // Some vars not related to problem
    },
    constructor: function(config) {
        this.initConfig(config);
    },
    initFileSystem: function(quota) {
        if(Ext.browser.is.PhoneGap && !Ext.os.is.Desktop) {
            Ext.device.FileSystem.requestFileSystem({     
                type: window.PERSISTENT,
                size: quota,
                success: this.initFsSuccess,
                failure: this.initFsFailure
            });
        } else {
            window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
            window.requestFileSystem(window.PERSISTENT, quota, this.initFsSuccess, this.initFsFailure);
        }
    },
    initFsSuccess: function(fs) {
        // Save file system reference
        MyApp.app.fS = fs;      
        alert("FS: " + fs.root.fullPath); // This line outputs "FS: undefined"
        fs.root.getFile("newFile.jpg", {create: true, exclusive: false}, function(fileEntry){ alert("GetFile OK"); }, function(error){ alert("GetFile ERR"); });
    },
    initFsFailure: function(err) {
        console.log("File System Error " + err.code);
        Ext.Msg.show({
            title: 'FyleSystem Error',
            message: 'Can\'t access to FileSystem',
            buttons: [ { itemId: 'ok', text: 'Ok', ui: 'decline' } ],
            fn: Ext.emptyFn
        });
    }
});

When I try to access file system's root full path (like in the first alert in "initFsSuccess" function), I get undefined as value. Furthermore, the "getFile" function stops executing (no callback is invoked, success or failure) and in LogCat I'm able to see this:

01-12 12:22:20.669: D/CordovaLog(1625): file:///android_asset/www/phonegap.js: Line 1059 : processMessage failed: Error: TypeError: Cannot call method 'error' of undefined
01-12 12:22:20.669: I/Web Console(1625): processMessage failed: Error: TypeError: Cannot call method 'error' of undefined at file:///android_asset/www/phonegap.js:1059
01-12 12:22:20.669: D/CordovaLog(1625): file:///android_asset/www/phonegap.js: Line 1060 : processMessage failed: Stack: TypeError: Cannot call method 'error' of undefined
01-12 12:22:20.669: D/CordovaLog(1625):     at [object Object].getFile (file:///android_asset/www/app.js:1:498661)
01-12 12:22:20.669: D/CordovaLog(1625):     at [object Object].<anonymous> (file:///android_asset/www/app.js:1:617018)
01-12 12:22:20.669: D/CordovaLog(1625):     at file:///android_asset/www/app.js:1:495077
01-12 12:22:20.669: D/CordovaLog(1625):     at file:///android_asset/www/plugins/org.apache.cordova.file/www/requestFileSystem.js:52:25
01-12 12:22:20.669: D/CordovaLog(1625):     at success (file:///android_asset/www/plugins/org.apache.cordova.file/www/fileSystems-roots.js:40:13)
01-12 12:22:20.669: D/CordovaLog(1625):     at Object.callbackFromNative (file:///android_asset/www/phonegap.js:293:54)
01-12 12:22:20.669: D/CordovaLog(1625):     at processMessage (file:///android_asset/www/phonegap.js:1054:21)
01-12 12:22:20.669: D/CordovaLog(1625):     at Function.processMessages (file:///android_asset/www/phonegap.js:1091:13)
01-12 12:22:20.669: D/CordovaLog(1625):     at pollOnce (file:///android_asset/www/phonegap.js:956:17)
01-12 12:22:20.669: D/CordovaLog(1625):     at pollOnceFromOnlineEvent (file:///android_asset/www/phonegap.js:946:5)
01-12 12:22:20.669: I/Web Console(1625): processMessage failed: Stack: TypeError: Cannot call method 'error' of undefined
01-12 12:22:20.669: I/Web Console(1625):     at [object Object].getFile (file:///android_asset/www/app.js:1:498661)
01-12 12:22:20.669: I/Web Console(1625):     at [object Object].<anonymous> (file:///android_asset/www/app.js:1:617018)
01-12 12:22:20.669: I/Web Console(1625):     at file:///android_asset/www/app.js:1:495077
01-12 12:22:20.669: I/Web Console(1625):     at file:///android_asset/www/plugins/org.apache.cordova.file/www/requestFileSystem.js:52:25
01-12 12:22:20.669: I/Web Console(1625):     at success (file:///android_asset/www/plugins/org.apache.cordova.file/www/fileSystems-roots.js:40:13)
01-12 12:22:20.669: I/Web Console(1625):     at Object.callbackFromNative (file:///android_asset/www/phonegap.js:293:54)
01-12 12:22:20.669: I/Web Console(1625):     at processMessage (file:///android_asset/www/phonegap.js:1054:21)
01-12 12:22:20.669: I/Web Console(1625):     at Function.processMessages (file:///android_asset/www/phonegap.js:1091:13)
01-12 12:22:20.669: I/Web Console(1625):     at pollOnce (file:///android_asset/www/phonegap.js:956:17)
01-12 12:22:20.669: I/Web Console(1625):     at pollOnceFromOnlineEvent (file:///android_asset/www/phonegap.js:946:5) at file:///android_asset/www/phonegap.js:1060
01-12 12:22:20.669: D/CordovaLog(1625): file:///android_asset/www/phonegap.js: Line 1061 : processMessage failed: Message: S01 File1432781697 [{"fullPath":"\/","filesystemName":"temporary","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/cache\/","filesystem":0,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"content","isDirectory":true,"nativeURL":"cdvfile:\/\/localhost\/content\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files-external","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"documents","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/files\/Documents\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"sdcard","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache-external","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"root","isDirectory":true,"nativeURL":"file:\/\/\/","filesystem":1,"isFile":false,"name":""}]
01-12 12:22:20.669: I/Web Console(1625): processMessage failed: Message: S01 File1432781697 [{"fullPath":"\/","filesystemName":"temporary","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/cache\/","filesystem":0,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"content","isDirectory":true,"nativeURL":"cdvfile:\/\/localhost\/content\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files-external","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"documents","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/files\/Documents\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"sdcard","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/com.mysite.MyApp\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache-external","isDirectory":true,"nativeURL":"file:\/\/\/mnt\/sdcard\/Android\/data\/com.mysite.MyApp\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"root","isDirectory":true,"nativeURL":"file:\/\/\/","filesystem":1,"isFile":false,"name":""}] at file:///android_asset/www/phonegap.js:1061

Thank you all in advice for any help, I'll try to provide any other infos/specs if needed.

1

There are 1 answers

0
MatteoBelfiori On BEST ANSWER

Found the solution (even if I don't known why...)! This is what I've done:

1) In my "app.js" file I've removed the

'Ext.device.FileSystem'

line from the "requires" section;

2) Replaced the body of the "initFileSystem()" function reported in first post, with this one

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(window.PERSISTENT, quota, this.initFsSuccess, this.initFsFailure);

It works in:

  • Google Chrome v. 39.0.2171.95 m (device mode on & off);
  • My samsung Galaxy S4 (GT-I9515) running official Android 4.4.2 (as native app, not through browser):
  • Android Emulator (I'm on a Windows 7 pc) running Android 4.1.1 with Intel Atom x86 as CPU