5

I am trying to create a file using the File system API..i googled and i get a code

function onFs(fs) {

  fs.root.getFile('log.txt', {create: true, exclusive: true},
      function(fileEntry) {
           fileEntry.getMetaData(function(md) {
            }, onError);

      },
      onError
  );
}

window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, onFs, onError);

can any one say what is the fs which is passed as function argument..

Please refer me a good example...

0

1 Answer 1

0

fs is a javascript object that allows you to make "system-like" level calls to a virtual filesystem.

So for instance you can use the fs object to create/get a reference to a file in the virtual filesystem with fs.root.getFile(...). The third argument (in your case, the following lines of code from your above snippet) in the .getFile(...) method happens to be a callback for successful obtaining of a file reference.

function(fileEntry) {
       fileEntry.getMetaData(function(md) {
        }, onError);
}

That file reference (in your case it is called fileEntry) can have various methods called such as .createWriter(...) for writing to files, .file(...) for reading files and .remove(...) for removing files. Your method calls .getMetaData(...) which contains a file size and modification date.

For more specifics as well as some good examples on the html5 file-system api you may find the following article helpful Exploring the File-System API

The location of the files differs on the browser, operating system and storage type (persistent vs. temporary) but the following link has served to be quiet useful as well Chrome persistent storage locations

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

2 Comments

i got "Error: SECURITY_ERR" when i do it in chrome...pls help
I found the new question you asked, My response on your SECURITY_ERR is in the second paragraph. I included example code and other explanations there as well

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.