最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome webkitStorageInfo.requestQuota - Stack Overflow

programmeradmin2浏览0评论

I'm trying to utilize local FS in Chrome. The first thing I do - request filesystem quota. The code below worked only once, making Chrome to show confirmation. But after that this code does nothing: no alert is displayed. What is wrong with this code?

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;     
window.webkitStorageInfo.requestQuota( 
            window.PERSISTENT,
            fsize,
            function( bytes ) {
                alert( "Quota is available: " + bytes );
            },
            function( e ) {
                alert( "Error allocating quota: " + e );
            }

);

I'm trying to utilize local FS in Chrome. The first thing I do - request filesystem quota. The code below worked only once, making Chrome to show confirmation. But after that this code does nothing: no alert is displayed. What is wrong with this code?

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;     
window.webkitStorageInfo.requestQuota( 
            window.PERSISTENT,
            fsize,
            function( bytes ) {
                alert( "Quota is available: " + bytes );
            },
            function( e ) {
                alert( "Error allocating quota: " + e );
            }

);
Share Improve this question asked Mar 29, 2012 at 11:59 Igor SemenovIgor Semenov 4835 silver badges13 bronze badges 2
  • You should use window.requestFileSystem.requestQuota... not window.webkitStorageInfo.requestQuota.... If not then the first line is pointless ;-). – Nux Commented Oct 2, 2012 at 8:39
  • Scratch that. The first line is pointless in this situation. Though you might want to try window.storageInfo = window.storageInfo || window.webkitStorageInfo; and wrap the call in some if so that it don't shout with errors in other browsers. – Nux Commented Oct 2, 2012 at 8:46
Add a ment  | 

3 Answers 3

Reset to default 4

Once the user has granted access to fsize quota, the browser won't reprompt them. Your success callback will be called without the info bar. The only way to see it again (for testing), is to request a larger fsize.

You could also try 'Clear browsing data' in settings to see if that resets things.

From http://www.html5rocks./en/tutorials/file/filesystem/:

"Once the user has granted permission, there's no need to call requestQuota() in the future (unless you wish to increase your app's quota). Subsequent calls for equal or lesser quota are a noop."

NB: This implies there's no way for an app to release quota that it no longer needs.

Resetting quota for testing

When you are testing storage in your app, you might want to clear the stored data so that you can test quota management afresh in your app. To do so:

  1. Enter chrome://settings/cookies in the omnibox (the address bar).
  2. Search for your app.
  3. Select your app.
  4. Click the X on the right side of the highlighted selection.

https://developers.google./chrome/whitepapers/storage

发布评论

评论列表(0)

  1. 暂无评论