JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – Filesystem API无法在Chrome v27和v29中运行大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试设置一个文件存储空间以供以后在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,function(fs) {
    console.log ('fs: ',arguments); // I see this on Chrome 27 in Ubuntu
  },onError);
}

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

大佬总结

以上是大佬教程为你收集整理的javascript – Filesystem API无法在Chrome v27和v29中运行全部内容,希望文章能够帮你解决javascript – Filesystem API无法在Chrome v27和v29中运行所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。