【问题标题】:Filesystem API not working in Chrome v27 & v29文件系统 API 在 Chrome v27 和 v29 中不起作用
【发布时间】:2013-06-18 08:59:56
【问题描述】:

我正在尝试设置文件存储以供以后在 Phonegap 中使用,但目前在 Chrome 中进行调试。按照html5rocks 中描述的方式,我只能向用户请求配额,但不会执行请求文件系统时的回调。见:

window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024*1024, function(grantedBytes) {
    requestFS(grantedBytes);
}, onError);

function requestFS(grantedBytes) {
    window.webkitRequestFileSystem(window.PERSISTENT, grantedBytes, function(fs) {
        // ... does not get called ###################################
    }, onError);
}

现在 Chrome 警告我 webkitStorageInfo 已被弃用,并且从今天开始有一个新标准 https://dvcs.w3.org/hg/quota/raw-file/tip/Overview.html。我尝试使用 navigator.webkitPersistentStorage 没有成功。

文件系统 API 是否可能当前无法正常工作或已被弃用,或者我的上述代码可能有问题?

下面的函数也不做任何事情,没有可见的错误:

navigator.webkitPersistentStorage.queryUsageAndQuota(function(usage, quota) {
    console.log(arguments);

    navigator.webkitPersistentStorage.requestQuota(1024 * 1024, function(grantedQuota) {
        console.log(arguments);

        window.webkitRequestFileSystem(window.PERSISTENT, 1024 * 1024, function(fs) {
            console.log(arguments);
        });
    });
});

更新:

我得到了 Eric Bidelman 的 Filer 工作,所以我的代码中一定有问题,尽管我看不出 Filer init 方法和我正在做的事情之间有什么区别。

【问题讨论】:

    标签: javascript html google-chrome cordova fileapi


    【解决方案1】:

    我正在运行 Chorme 27,以下似乎可以正常工作,显示指示的日志消息

    function onError () { console.log ('Error : ', arguments); }
    
    navigator.webkitPersistentStorage.requestQuota (1024*1024*1024, function(grantedBytes) {
      console.log ('requestQuota: ', arguments);
      requestFS(grantedBytes);
    }, onError);
    
    function requestFS(grantedBytes) {
      window.webkitRequestFileSystem(window.PERSISTENT, grantedBytes, function(fs) {
        console.log ('fs: ', arguments); // I see this on Chrome 27 in Ubuntu
      }, onError);
    }
    

    基本上我将您原始代码中的window.webkitStorageInfo.requestQuota 更改为navigator.webkitPersistentStorage.requestQuota 并删除了PERSISTENT 参数

    【讨论】:

    • 但这正是我所做的,不是吗?我猜失败更复杂,因为我将它插入到现有的广泛应用程序中。无论如何,感谢您试用它,Filer.js 让我走上了正轨。
    • 我在 chrome 27.0.1453.116 上运行,但此代码不起作用.. :\ 我收到 FileError.INVALID_MODIFICATION_ERR
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    相关资源
    最近更新 更多