Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  31] [ 2]  / answers: 1 / hits: 34612  / 11 Years ago, tue, july 23, 2013, 12:00:00

So there is a similar post found here html-5-filesystem-access-type-error. However, I'm not very satisfied with the conclusion because I do not feel it actually answered the question - the solution given is the deprecated code solution. Does anyone know how to use navigator instead of window as the Chrome console is informing to do?



I have been using the following and it works, but the chrome console keeps informing me not to do so because it is deprecated.



Working Deprecated Code



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


Note: onInitFs and errorHandler are both functions defined elsewhere, that work.



Console Log - The message I get in the console is as follows:



'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage'
or 'navigator.webkitPersistentStorage' instead.


So the best practice would be to stop using the deprecated method. Unfortunately, when I replace window with navigator it crashes (see below). How does one use navigator instead of window to access the file system?


More From » html

 Answers
40

Below are two examples with the current API.



It uses navigator.webkitPersistentStorage.requestQuota instead of the deprecated window.webkitStorageInfo.queryUsageAndQuota:



Query Quota



navigator.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {
console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
},
function(e) { console.log('Error', e); }
);


Request Quota



var requestedBytes = 1024*1024*280; 

navigator.webkitPersistentStorage.requestQuota (
requestedBytes, function(grantedBytes) {
console.log('we were granted ', grantedBytes, 'bytes');

}, function(e) { console.log('Error', e); }
);


You have to choose either temporary (webkitTemporaryStorage) or persistent (webkitPersistentStorage) storage to query.



The current Chrome implementation tracks this specific spec version, which describes things a bit more: http://www.w3.org/TR/2012/WD-quota-api-20120703/



chromestore.js provides an easier API for this data.






To answer your original question, your new code would look like this:



Request quota and initialize filesystem



var requestedBytes = 1024*1024*280; 

navigator.webkitPersistentStorage.requestQuota (
requestedBytes, function(grantedBytes) {
window.webkitRequestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);

}, function(e) { console.log('Error', e); }
);

[#76804] Monday, July 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dewayneh

Total Points: 538
Total Questions: 114
Total Answers: 97

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
;