Html 5文件系统API,我得到一个DOMError“;NotSupporteError”;

Html 5 File system API, I am getting a DOMError "NotSupporteError"

本文关键字:一个 DOMError NotSupporteError API 文件系统 Html      更新时间:2023-09-26

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

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

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

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

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