javascript - Html 5 文件系统 API,我收到 DOMError "NotSupporteError"

标签 javascript html google-chrome html5-filesystem

我正在尝试在 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,但我得到了完全相同的错误。

最佳答案

我想你的问题可能出在这里:

The application has been only tested locally (i.e. just open the html file with Chrome).

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

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

关于javascript - Html 5 文件系统 API,我收到 DOMError "NotSupporteError",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20594804/

相关文章:

javascript - 如何解决错误 "THREE.GLTFLoader: Failed to load buffer "scene.bin“。”?

javascript - element.setAttribute ('prop' ,value) vs element.prop = value

ios - 为什么 Modernizr 为 iOS 设备设置拖放类

google-chrome - 有没有办法在安装时自动固定 Chrome 扩展程序?

javascript - fetch() 的背压在 Google Chrome 中不起作用

javascript - 讲require、import、packages的node-way是什么?

javascript - 自定义文件上传脚本在 safari 中不起作用

html - Bootstrap 中的居中对齐菜单

google-chrome - Chrome "throttling"打开/关闭热键

javascript - 在 Javascript 中为 JSON 对象赋值