I hear that Firefox 3.6 adds support for the HTML local file API (Announcement here).
Does this mean that I can access local files from javascript?
Can anyone point me to examples for reading / writing local files?
I would love to be able to read / write simple text files.
Before the HTML5 file API can access a file from the local file system, the user has to select the file to give access to. For security reasons selecting files is done via the <input type="file"> HTML element. Here is an input element example: By itself the input element is not enough. You need an onchange listener too. Here is how that looks:
HTML5: FileSystem API – Create Files and Store Them Locally Using JavaScript and Webkit. The FileSystem-API allows the creation of files and folders as well as their local storage using JavaScript.
The HTML5 file API enables JavaScript inside HTML5 pages to load and process files from the local file system. Via the HTML5 file API it is possible for JavaScript to process a file locally, e.g. compress, encode or encrypt it, or upload the file in smaller chunks. Of course the HTML5 file API raises some security concerns.
HTML5 saw the introduction of a number of new APIs that can be used to handle files in the browser. These APIs make it much easier to accomplish tasks like reading and writing files or uploading a file created using JavaScript.
The only files you can access are files dropped from the desktop or files that has been selected from an <input/>
tag. See the demo I've written here: http://hacks.mozilla.org/2009/12/uploading-files-with-xmlhttprequest/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With