abilash
abilash

Reputation: 897

Simple example with window.requestFileSystem() function

I have next problem: I try to use window.requestFileSystem() function in Chrome, but it failed. Look for my steps:

1)I added 'allow file access from file' flag to Chrome(see img bellow):enter image description here

2)I restarted the system.

3)Then I ran the Chrome with 'allow file access file' flag.

4) After all I try to launch this sample code:

function onInitFs(fs) {
  console.log('Opened file system: ' + fs.name);
}

    function errorHandler(e)
{
    console.log("Error");
}    
    window.requestFileSystem(window.TEMPORARY, 5*1024*1024 /*5MB*/, onInitFs, errorHandler);

but It failed: enter image description here

What's wrong in my actions?

Upvotes: 5

Views: 30184

Answers (4)

COBRA.cH
COBRA.cH

Reputation: 147

This code works for me in chrome. I actually used it for phonegap, but I tested it first on chrome on my notebook and a yellow bar appeared on the top of the browser, asking me to allow the web app permanent storage on my local drive.

    navigator.webkitPersistentStorage.requestQuota(1024*1024, 
        function(grantedBytes) {
            window.requestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
        }, 
        function(errorCode) {
            alert("Storage not granted.");
        }
    );

Upvotes: -1

user3062037
user3062037

Reputation: 9

You should change

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 

to

window.RequestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 

(The R should have been capitalized.)

Upvotes: -4

puneet
puneet

Reputation: 116

open chrome from command line using below command

chrome --allow-file-access-from-files

Upvotes: -2

ndm
ndm

Reputation: 60493

That's because this functionality is currently only availble prefixed, ie window.webkitRequestFileSystem

You may find this turorial interesting: http://www.html5rocks.com/en/tutorials/file/filesystem/

Upvotes: 14

Related Questions