Getting FileError when trying to use HTML5 api file in Google Chrome

I tried to create a file using the file system API in chrome. I initially tried the PERSISTENT repository as follows

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
webkitStorageInfo.requestQuota(webkitStorageInfo.PERSISTENT, 1024*1024, 
    function(grantedBytes) {
        window.requestFileSystem(webkitStorageInfo.PERSISTENT, grantedBytes, onInitFs, 
        errorHandler);
    }, 
    errorHandler);

At first it worked fine. But now, when I try to use the same code, I get the following error:

NOT_SUPPORTED_ERR: DOM Exception 9

Then I tried storing the TEMPORARY file as follows

window.requestFileSystem(TEMPORARY, 1024*1024, onInitFs, errorHandler);

This gives me some FileError with code 2, which means Security Error. Can anyone help me on these issues?

+3
source share
2 answers

Are you trying to put code on a page stored on your local computer and run it using Chrome? Did you add a flag

--allow-file-access-from-files

Chrome? , , , .

+2

. , API- script, . - ? , , .

manifest.json:

{
  "name": "Testing FS",
  "manifest_version":2,
  "version": "1.0",
  "content_scripts": [
    {
      "matches":["*://*.google.com/*"],
      "js":["script.js"]
    }
  ]
}

script.js

webkitStorageInfo.requestQuota(webkitStorageInfo.TEMPORARY, 1024*1024, function(grantedBytes) {
    console.log("bytes granted: ", grantedBytes);
    window.webkitRequestFileSystem(webkitStorageInfo.TEMPORARY, grantedBytes, onInitFs, errorHandler)
}, errorHandler);

function errorHandler(e) {
  console.log("FS error", e);
}

function onInitFs(fs) {
  fs.root.getFile('log.txt', {create: true}, function(fileEntry) {
      console.log(fileEntry);
  }, errorHandler);
}
0

All Articles