文件和目录条目 API

非标
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 浏览器兼容性 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 拖放 . 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 了解更多细节。

访问文件系统

There are two ways to get access to file systems defined in the current specification draft:

异步 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
表示文件系统。
FileSystemEntry
The basic interface representing a single entry in a file system. This is implemented by other interfaces which represent files or directories.
FileSystemFileEntry
表示文件系统中的单个文件。
FileSystemDirectoryEntry
表示文件系统中的单个目录。
FileSystemDirectoryReader
创建通过调用 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 文件和目录条目 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() .

同步 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
表示文件系统。
FileSystemEntrySync
The basic interface representing a single entry in a file system. This is implemented by other interfaces which represent files or directories.
FileSystemFileEntrySync
表示文件系统中的单个文件。
FileSystemDirectoryEntrySync
表示文件系统中的单个目录。
FileSystemDirectoryReaderSync
创建通过调用 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() .

其它接口

LocalFileSystem
使您可以访问沙盒文件系统。
LocalFileSystemSync
LockedFile
提供采用所有必要锁来处理给定文件的工具。
Metadata

规范

规范 状态 Comment
文件和目录条目 API 草案 提议 API 草案

此 API 没有正式的 W3C 或 WHATWG 规范。

浏览器兼容性

FileSystem

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
FileSystem Chrome 7
Alternate Name
7
Alternate Name
Alternate Name Uses the non-standard name: DOMFileSystem
Edge ≤18
Prefixed
≤18
Prefixed 注意事项
Prefixed Implemented with the vendor prefix: WebKit
注意事项 Edge only supports this API in drag-and-drop scenarios using the the DataTransferItem.webkitGetAsEntry() method. It's not available for use in file or folder picker panels (such as when you use an <input> element with the HTMLInputElement.webkitdirectory 属性。
Firefox 50 IE 不支持 No Opera 15
Prefixed
15
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari 11.1 WebView Android ≤37
Alternate Name
≤37
Alternate Name
Alternate Name Uses the non-standard name: DOMFileSystem
Chrome Android 18
Alternate Name
18
Alternate Name
Alternate Name Uses the non-standard name: DOMFileSystem
Firefox Android 50 Opera Android 14
Prefixed
14
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 11.3 Samsung Internet Android 1.0
Prefixed
1.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit

图例

完整支持
完整支持
不支持
不支持
见实现注意事项。
见实现注意事项。
使用非标名称。
使用非标名称。
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

FileSystemSync property

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
FileSystemSync
非标
Chrome 13
Prefixed
13
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge ≤79
Prefixed
≤79
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox 不支持 No IE 不支持 No Opera 15
Prefixed
15
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari 6
Prefixed
6
Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android ≤37
Prefixed
≤37
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android 18
Prefixed
18
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 不支持 No Opera Android 14
Prefixed
14
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 6
Prefixed
6
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Samsung Internet Android 1.0
Prefixed
1.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit

图例

完整支持
不支持
不支持
非标。预期跨浏览器支持较差。
非标。预期跨浏览器支持较差。
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

另请参阅