简体   繁体   English

HTML5:文件系统API Chrome 30-意外的errorHandler调用

[英]HTML5: Filesystem API Chrome 30 - Unexpected errorHandler call

I have following code in my app.js: 我的app.js中有以下代码:

function onInitFs(fs) {
    aGlobalFsRoot = fs.root;
    console.log('04Position');
    alert("Welcome to Filesystem! It's showtime :)"+fs); // Just to check if everything is OK :)
}

function openFS() {
navigator.webkitPersistentStorage.requestQuota (1*1024*1024, function(grantedBytes) {
  console.log ('test1');
  reqFS(grantedBytes);
}, errorHandler);
}

function reqFS(grantedBytes) {
  window.webkitRequestFileSystem(window.PERSISTENT, grantedBytes, function(fs) {
    console.log ('test2');
    alert("Welcome to Filesystem! It's showtime :)"+fs); // Just to check if everything is OK :)
  }, errorHandler);
}

function errorHandler(e) {
  var msg = '';

  switch (e.code) {
    case FileError.QUOTA_EXCEEDED_ERR:
      msg = 'QUOTA_EXCEEDED_ERR'+e;
      break;
    case FileError.NOT_FOUND_ERR:
      msg = 'NOT_FOUND_ERR'+e;
      break;
    case FileError.SECURITY_ERR:
      msg = 'SECURITY_ERR z.B. Speicherplatz wurde abgelehnt.'+e;
      break;
    case FileError.INVALID_MODIFICATION_ERR:
      msg = 'INVALID_MODIFICATION_ERR'+e;
      break;
    case FileError.INVALID_STATE_ERR:
      msg = 'INVALID_STATE_ERR'+e;
      break;
    default:
      msg = 'Unknown Error'+e;
      break;
  };

  console.log('Error: ' + msg);
}

openFS is called on pageload. 在页面加载时调用openFS。 The code is based on this topic (where it also doesn't seem to work for newer versions of chrome). 该代码基于主题(在新版本的chrome中似乎也不起作用)。 I can't get it to work. 我无法正常工作。 All the time, the errorHandler is called. 一直以来,都会调用errorHandler。 It makes no difference if the filesystem already exists or not. 文件系统是否已经存在没有关系。 The quota seems to work. 配额似乎有效。

I get two different console logs: 我得到两个不同的控制台日志:

  1. When accsess is granted by user: 当用户授予访问权限时:

    Error: Unknown Error[object DOMError] app.js:81 错误:未知错误[对象DOMError] app.js:81

  2. When access is denied by user: 当用户拒绝访问时:

    test1 app.js:45 Error: SECURITY_ERR zB Speicherplatz wurde abgelehnt.[object FileError] app.js:81 test1 app.js:45错误:SECURITY_ERR zB Speicherplatz wurde abgelehnt。[对象FileError] app.js:81

Anyone got this working? 任何人都可以工作吗?

For everyone who comes along this thread... this solution works. 对于遇到此问题的每个人……此解决方案有效。 The problem was about the cookies. 问题出在饼干上。 In a freshly installed chrome 30, this works for me. 在新安装的chrome 30中,这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM