{{APIRef("File System API")}}{{Non-standard_header}}
The File and Directory Entries API simulates a local file system that web apps can navigate within. You can develop apps which read, write, and create files and/or directories in a virtual, sandboxed file system.
Before continuing, you should be aware that this is not a standardized API and it's very possible that code written to use it will not work on all browsers.
Two very similar APIs exist depending on whether you desire asynchronous or synchronous behavior. The synchronous API is indended to be used inside a {{domxref("Worker")}} and will return the values you desire. The asynchronous API will not block and functions and the API will not return values; instead, you will need to supply a callback function to handle the response whenever it arrives.
Asynchronous API
The asynchronous API should be used for most operations, to prevent file system accesses from blocking the entire browser if used on the main thread. It includes the following interfaces:
- LocalFileSystem has two global methods that lets you request access to a sandboxed file system: requestFileSystem() and resolveLocalFileSystemURL(). The methods are implemented by both the window object and the worker global scope.
- FileSystem represents a file system. The object is your gateway to the entire API.
- Entry represents an entry in a file system. The entry can be a file or a directory.
- DirectoryEntry represents a directory in a file system.
- DirectoryReader lets you read files and directories in a directory.
- FileEntry represents a file on a file system.
- FileError is an error that you might encounter while using the asynchronous methods.
Synchronous API
The synchronous API is for use with WebWorkers. Unlike the asynchronous API, the synchronous API does not use callbacks because the API methods return values.
- LocalFileSystemSync has two global methods that lets you request access to a sandboxed file system: requestFileSystemSync() and resolveLocalFileSystemSyncURL(). The methods are implemented by the worker object.
- FileSystemSync represents a file system.
- EntrySync represents an entry in a file system. The entry can be a file or a directory.
- DirectoryEntrySync represents a directory on a file system.
- DirectoryReaderSync lets you read files and directories in a directory.
- FileEntrySync represents a file on a file system.
- FileException is an error that you might encounter while using the synchronous methods.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('File System API')}} | {{Spec2('File System API')}} | Draft of proposed API |
This API has no official W3C or WHATWG specification.
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Asynchronous API | 13 {{ property_prefix("webkit") }} | {{ CompatGeckoDesktop(50) }}[1] | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} |
Synchronous API | 13 {{ property_prefix("webkit") }} | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Asynchronous API | {{ CompatNo }} | {{ CompatVersionUnknown }} {{ property_prefix("webkit") }} | {{ CompatGeckoMobile(50) }}[1] | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} |
Synchronous API | {{ CompatNo }} | {{ CompatVersionUnknown }} {{ property_prefix("webkit") }} | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} |
[1] Firefox 50 introduces partial support for the File and Directory Entries API. Be sure to check the compatibility tables for individual interfaces and methods before using them, to ensure that they're supported, before you use them. The API can be disabled by setting the value of the preference dom.webkitBlink.filesystem.enabled
to false
.
See also
- Introduction to the File and Directory Entries API