Non-standard This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
The File and Directory Entries API simulates a local file system that web apps can navigate within and access files in. You can develop apps which read, write, and create files and/or directories in a virtual, sandboxed file system.
Because this is a non-standard API, whose specification is not currently on a standards track, it's important to keep in mind that not all browsers implement it, and those that do may implement only small portions of it. Check the Browser compatibility section for details.
Two very similar APIs exist depending on whether you desire asynchronous or synchronous behavior. The synchronous API is intended to be used inside a 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.
The Firefox implementation of the File and Directory Entries API is very limited; there is no support for creating files. Only for accessing files which are selected by the user in a file <input>
element (see HTMLInputElement
as well) or when a file or directory is provided to the Web site or app using drag and drop. Firefox also does not implement the synchronous API. Check the browser compatibility for any part of the API you use carefully, and see File and Directory Entries API support in Firefox for more details.
Getting access to a file system
There are two ways to get access to file systems defined in the current specification draft:
- When handling a
drop
event for drag and drop, you can callDataTransferItem.webkitGetAsEntry()
to get theFileSystemEntry
for a dropped item. If the result isn'tnull
, then it's a dropped file or directory, and you can use file system calls to work with it. - The
HTMLInputElement.webkitEntries
property lets you access theFileSystemFileEntry
objects for the currently selected files, but only if they are dragged-and-dropped onto the file chooser (bug 1326031). IfHTMLInputElement.webkitdirectory
istrue
, the<input>
element is instead a directory picker, and you getFileSystemDirectoryEntry
objects for each selected directory.
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:
FileSystem
- Represents a file system.
FileSystemEntry
- The basic interface representing a single entry in a file system. This is implemented by other interfaces which represent files or directories.
FileSystemFileEntry
- Represents a single file in a file system.
FileSystemDirectoryEntry
- Represents a single directory in a file system.
FileSystemDirectoryReader
- Created by calling
FileSystemDirectoryEntry.createReader()
, this interface provides the functionality which lets you read the contents of a directory. FileSystemFlags
- Defines a set of values which are used when specifying option flags when calling certain methods in the File and Directory Entries API.
FileError
'- Represents an error which is generated by asynchronous file system calls.
There are also two global functions (which are not part of the specification at this time and are implemented only by Google Chrome). They're available on the Window
object and implemented in LocalFileSystem
: requestFileSystem()
and resolveLocalFileSystemURL()
.
Synchronous API
The synchronous API is should only be used in Worker
s; these calls block until they're finished executing, and simply return the results instead of using callbacks. Using them on the main thread will block the browser, which is naughty. The interfaces below otherwise mirror the ones from the asynchronous API.
FileSystemSync
- Represents a file system.
FileSystemEntrySync
- The basic interface representing a single entry in a file system. This is implemented by other interfaces which represent files or directories.
FileSystemFileEntrySync
- Represents a single file in a file system.
FileSystemDirectoryEntrySync
- Represents a single directory in a file system.
FileSystemDirectoryReaderSync
- Created by calling
FileSystemDirectoryEntrySync.createReader()
, this interface provides the functionality which lets you read the contents of a directory. FileException
'- Represents an error which is generated by synchronous file system calls.
There are also two global functions (which are not part of the specification at this time and are implemented only by Google Chrome). They're available on the Worker
object and implemented in LocalFileSystemSync
: requestFileSystemSync()
and resolveLocalFileSystemSyncURL()
.
Other Interfaces
Gives you access to a sandboxed file system.
Provides tools to deal with a given file with all the necessary locks.
Metadata
'
Specifications
Specification | Status | Comment |
---|---|---|
File and Directory Entries API | Draft | Draft of proposed API |
This API has no official W3C or WHATWG specification.
Browser compatibility
FileSystem
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
FileSystem
|
Chrome Full support 7 Full support 7 Alternate Name' Uses the non-standard name: |
Edge Full support ≤18 Full support ≤18 Prefixed' Implemented with the vendor prefix: WebKit
Notes' Edge only supports this API in drag-and-drop scenarios using the the |
Firefox
Full support 50 |
IE
No support No |
Opera Full support 15 Full support 15 Prefixed' Implemented with the vendor prefix: webkit |
Safari
Full support 11.1 |
WebView Android Full support ≤37 Full support ≤37 Alternate Name' Uses the non-standard name: |
Chrome Android Full support 18 Full support 18 Alternate Name' Uses the non-standard name: |
Firefox Android
Full support 50 |
Opera Android Full support 14 Full support 14 Prefixed' Implemented with the vendor prefix: webkit |
Safari iOS
Full support 11.3 |
Samsung Internet Android Full support 1.0 Full support 1.0 Prefixed' Implemented with the vendor prefix: webkit |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
- Uses a non-standard name.'
- Uses a non-standard name.
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
FileSystemSync
property
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome Full support 13 Full support 13 Prefixed' Implemented with the vendor prefix: webkit |
Edge Full support ≤79 Full support ≤79 Prefixed' Implemented with the vendor prefix: webkit |
Firefox
No support No |
IE
No support No |
Opera Full support 15 Full support 15 Prefixed' Implemented with the vendor prefix: webkit |
Safari Full support 6 Full support 6 Prefixed' Implemented with the vendor prefix: webkit |
WebView Android Full support ≤37 Full support ≤37 Prefixed' Implemented with the vendor prefix: webkit |
Chrome Android Full support 18 Full support 18 Prefixed' Implemented with the vendor prefix: webkit |
Firefox Android
No support No |
Opera Android Full support 14 Full support 14 Prefixed' Implemented with the vendor prefix: webkit |
Safari iOS Full support 6 Full support 6 Prefixed' Implemented with the vendor prefix: webkit |
Samsung Internet Android Full support 1.0 Full support 1.0 Prefixed' Implemented with the vendor prefix: webkit |
Legend
- Full support
- Full support
- No support
- No support
- Non-standard. Expect poor cross-browser support.'
- Non-standard. Expect poor cross-browser support.
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
See also
- Introduction to the File and Directory Entries API
- File and Directory Entries API support in Firefox
File and Directory Entries API by Mozilla Contributors is licensed under CC-BY-SA 2.5.