文件系统API不工作在Chrome v27 &v29

Filesystem API not working in Chrome v27 & v29

本文关键字:v27 v29 Chrome API 工作 文件系统      更新时间:2023-09-26

我正在尝试设置一个文件存储供以后在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方法和我正在做的事情之间的差异。

我正在运行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参数