1

查找存储后,我想尝试重置临时存储以进行测试。

window.webkitStorageInfo.requestQuota(webkitStorageInfo.TEMPORARY, 5*1024*1024,  
    function( bytes ) {
        console.log( "Quota is available: " + bytes );
    },
    function( e ) {
        console.log( "Error allocating quota: " + e );
    }); 

window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY, 
    //the type can be either TEMPORARY or PERSISTENT
    function(used, remaining) {
        console.log("Used quota: " + used + ", current quota: " + remaining);
    }, function(e) {
         console.log('Error', e); 
    });

requestQuota() 设置临时存储大小,而 queryUsageAndQuota() 告诉我当前配额是多少。但是,当我在 chrome 浏览器中查看控制台日志时,虽然设置了新配额,但queryUsageAndQuota(). 我得到的东西看起来像:

Quota is available: 5242880
Used quota: 0, current quota: 214748364

即使我预计什么是可用的和当前的配额是相同的。这是为什么?

4

1 回答 1

2

比较这两个输出

代码 1

window.webkitStorageInfo.requestQuota(webkitStorageInfo.TEMPORARY, 
             5188955171*1024*1024,  
    function( bytes ) {
        console.log( "Quota is available: " + bytes );
    },
    function( e ) {
        console.log( "Error allocating quota: " + e );
    }); 

window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY, 
    //the type can be either TEMPORARY or PERSISTENT
    function(used, remaining) {
        console.log("Used quota: " + used + ", current quota: " + remaining);
    }, function(e) {
         console.log('Error', e); 
    });

输出 1

Quota is available: 5188982205
Used quota: 492, current quota: 5188982205

代码 2

window.webkitStorageInfo.requestQuota(webkitStorageInfo.TEMPORARY, 5*1024*1024,  
    function( bytes ) {
        console.log( "Quota is available: " + bytes );
    },
    function( e ) {
        console.log( "Error allocating quota: " + e );
    }); 
window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY, 
    //the type can be either TEMPORARY or PERSISTENT
    function(used, remaining) {
        console.log("Used quota: " + used + ", current quota: " + remaining);
    }, function(e) {
         console.log('Error', e); 
    });

输出 2

Quota is available: 5242880
Used quota: 0, current quota: 214748364

在您的情况下,您请求了一个5242880已经可用且小于可用数量的次要配额,因此它返回一个successCallback请求配额!通过请求大量重置配额!

window.webkitStorageInfo.requestQuota用于请求比可用存储更多的存储空间,但是 Chrome 会自动为您的应用提供临时存储空间,因此您不需要请求分配(最多 20% 的共享池)

参考

于 2013-01-08T18:10:39.693 回答