3

I was trying to create a file using the file system API in chrome. Initially I tried PERSISTENT storage as follows

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

It was working fine initially. But now when I try the same code is giving me the following error

NOT_SUPPORTED_ERR: DOM Exception 9

Then I tried TEMPORARY file storage as follows

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

That is giving me some FileError with the code 2 which means Security Error. Can anyone please help me on these issues?

6
  • Could the second error actually be from your onInitFs callback doing something illegal with your DOMFileSystem object? Commented May 8, 2012 at 15:54
  • No the program control is not reaching onInitFs. I tried using the webkitStorageInfo.queryUsageAndQuota function before requesting for a quota. This is returning 0 bytes as the available bytes. That is the issue i guess. Is there any way to get quota? Why is this 0 for me? Commented May 8, 2012 at 19:02
  • Try adding unlimitedStorage to your permissions and see if it helps. If not, I'm really not sure what's wrong. Commented May 8, 2012 at 19:29
  • Adding unlimitedStorage helps to get the quota. But still the FileError haunts me when I try to call getFile Commented May 9, 2012 at 4:22
  • Where exactly are you making the request? Background page, popup, or content script? Commented May 9, 2012 at 13:16

2 Answers 2

2

Are you trying to place the code in a page that is stored on your local computer and run it with Chrome? Did you add the flag

--allow-file-access-from-files

in your Chrome shortcut? I happened to encounter the same error as yours and suddenly I realized that I forgot to add this flag to run my chrome.

Sign up to request clarification or add additional context in comments.

Comments

0

I can't reproduce your error. I made a simple extension that uses the filesystem API in a content script and it works fine for me. Do you get any errors on your console? If not, build off this code and see if you get any more errors.

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.