1

尝试使用沙盒文件系统 API 创建文件:

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;     
window.requestFileSystem(
    window.PERSISTENT, 
    1024 * 1024, 
    function( fs ) {       
        fs.root.getFile( 'test.txt', {create: true}, function( fe )
        {
            alert( "OK" );
        }, function( e )
        {
            alert( e.code );
        }
        );
    }, null
);

我总是QUOTA_EXCEEDED_ERR在此代码上收到错误代码 10 ( )。

Chrome: 17.0.963.79 m,以--allow-file-access-from-files标志开头。

我究竟做错了什么?

4

2 回答 2

2

对于持久存储,您必须明确请求用户的许可:

webkitStorageInfo.requestQuota( 
  webkitStorageInfo.PERSISTENT,

  1000, // amount of bytes you need

  function(availableBytes) {
    alert("Quota is available. Quota size: " + availableBytes);
    // you can use the filesystem now
  }
);

您也可以选择临时存储。

于 2012-03-16T10:29:34.687 回答
0

pimvdb 的非常有用的答案。截至目前(2013 年 10 月)Chrome 报告webkitStorageInfo为已弃用。相反,更喜欢以下内容:

navigator.webkitPersistentStorage.requestQuota(
  2048, //bytes of storage requested
  function(availableBytes) { 
    console.log(availableBytes);
  }
);

要请求临时存储,请使用navigator.webkitTemporaryStorage.requestQuota

于 2013-10-23T17:33:51.627 回答