FileSystem root.fullPath返回undefined,root.getFile在phonegap.js中给出“processMessage failed error”

时间:2015-01-12 12:32:49

标签: cordova html5-filesystem sencha-cmd5 senchatouch-2.4

这是我的第一个问题,很抱歉,如果我写错了我的要求。我使用命令

使用Sencha Touch 2.4.1和PhoneGap(我的主要目标是Android)创建项目
sencha app build native

打包。简而言之,我需要请求文件系统,然后下载一些文件(图像)。根据像this这样的帖子,我试图使用" getFile()"在开始下载之前的功能,但即使是这样的简单代码也会给我带来麻烦:

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
        });
    }
});

当我尝试访问文件系统的根完整路径时(如在" initFsSuccess"函数中的第一个警报中),我得到undefined作为值。此外," getFile"函数停止执行(没有调用回调,成功或失败),在LogCat中我能看到这个:

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

感谢所有人提供任何帮助,如果需要,我会尝试提供任何其他信息/规格。

1 个答案:

答案 0 :(得分:1)

找到解决方案(即使我不知道为什么......)!这就是我所做的:

1)在我的“app.js”文件中,我删除了

'Ext.device.FileSystem'

来自“要求”部分的行;

2)替换了第一篇文章中报道的“initFileSystem()”函数的主体,用这一个

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

适用于:

  • Google Chrome v.39.0.2171.95 m(设备模式开启和关闭);
  • 我的三星Galaxy S4(GT-I9515)运行官方Android 4.4.2(作为原生应用,不通过浏览器):
  • 使用Intel Atom x86作为CPU运行Android 4.1.1的Android模拟器(我在Windows 7上)