5

我正在开发一个 webapp,我正在尝试使用文件系统 API 访问目录。在根据规范访问目录之前,我需要向用户请求配额。我应该做这样的事情:

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

每次我这样做时,我都会收到一条**TypeError: Type error**消息。请问我做错了什么?提前致谢。
注意:onInitFs 和 errorHandler 已定义,我只是没有在此处包含代码。

4

2 回答 2

5

我遇到了同样的问题,有人发布了解决方案,在filesystem-api-not-working-in-chrome-v27-v29 找到

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

你必须PERSISTENTnavigator.webkitPersistentStorage.requestQuota(...)

于 2013-07-23T12:53:30.557 回答
0

这个版本,来自https://developers.google.com/chrome/whitepapers/storage似乎至少可以走得更远:

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

它是窗口而不是导航器...

于 2013-06-14T21:22:06.403 回答