【问题标题】:Html 5 File system API, I am getting a DOMError "NotSupporteError"Html 5 文件系统 API,我收到 DOMError "NotSupporteError"
【发布时间】:2013-12-15 21:02:49
【问题描述】:

我正在尝试在 chrome 31 中使用 HTML5 文件系统 API。不幸的是,在用户授予对文件系统配额的访问权限后,我收到错误消息。

这是错误:

Error DOMError {message: "The implementation did not support the requested type of object or operation.", name: "NotSupportedError"} 

我正在使用的代码:

<!DOCTYPE html> 
<html> 
  <head> 
  <title> JavaScript File System </title> 
  <script>
    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;


    navigator.webkitPersistentStorage.requestQuota(1024*1024, function(grantedBytes) {
         window.requestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);
          }, function(e) {
         console.log('Error', e);
     }); 

    function onInitFS(fs){
      alert("Welcome to Filesystem! It's showtime :)"); // Just to check if everything is OK :)
        // place the functions you will learn bellow here
        }

  function errorHandler(e) {
    var msg = '';
    switch (e.code) {
      case FileError.QUOTA_EXCEEDED_ERR:
        msg = 'QUOTA_EXCEEDED_ERR';
        break;
      case FileError.NOT_FOUND_ERR:
        msg = 'NOT_FOUND_ERR';
        break;
      case FileError.SECURITY_ERR:
        msg = 'SECURITY_ERR';
        break;
      case FileError.INVALID_MODIFICATION_ERR:
        msg = 'INVALID_MODIFICATION_ERR';
        break;
      case FileError.INVALID_STATE_ERR:
        msg = 'INVALID_STATE_ERR';
        break;
      default:
        msg = 'Unknown Error';
        break;
    };

    console.log('Error: ' + msg);
  }
   </script> 
  </head> 
  <body> 
  </body> 
</html>

该应用程序仅在本地进行了测试(即仅使用 Chrome 打开 html 文件)。

我也尝试了 filer.js,但我得到了完全相同的错误。

【问题讨论】:

    标签: javascript html google-chrome html5-filesystem


    【解决方案1】:

    我认为你的问题可能在这里:

    该应用程序仅在本地进行了测试(即只需使用 Chrome 打开 html 文件)。

    当您在 file:/// 协议上运行时,您不会获得与 http/s:/// 相同的权限

    如果我是你,我会尝试通过网络服务器运行它。

    【讨论】:

    • 好的,我试试。但是,应该有一种方法可以在本地对其进行测试,因为我无法开发 HTML 应用程序并为我所做的每个更改进行部署。
    • 花几分钟时间为自己安装一个本地网络服务器是非常值得的。有些安装程序或多或少可以做所有事情:Windows (ampps.com) | Mac (mamp.info)
    • 很高兴听到这个消息。这样的事情会让你发疯。为自己的理智投资本地网络服务器!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 2013-10-13
    • 1970-01-01
    • 2022-11-17
    • 2019-08-23
    • 1970-01-01
    相关资源
    最近更新 更多