javascript - 文件系统 API 在 Chrome v27 和 v29 中不起作用

标签 javascript html google-chrome cordova fileapi

我正在尝试设置一个文件存储以供以后在 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);
        });
    });
});

更新:

我得到了 Filer由 Eric Bidelman 工作,所以我的代码中一定有错误,尽管我看不出 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 参数

关于javascript - 文件系统 API 在 Chrome v27 和 v29 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17164698/

相关文章:

html - 将 Twitter Bootstrap 图标添加到输入框

javascript - 在悬停时突出显示一个元素

javascript - D3 替换数据并重新启动模拟后,并非所有节点都更新

javascript - Angular - 将数据传递给嵌套指令

javascript - 覆盖 retry-axios 默认配置

html - css 过渡属性不适用于悬停

javascript - 使用 javascript/jquery 从 json 变量获取 json 字符串名称

javascript - 一页中的 jquery 表单验证和 php 脚本

javascript - window.location.href - 资源被解释为文档但以 MIME 类型传输

java - 使用小程序减少 HTML