非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。

文件和目录条目 API 模拟本地文件系统,Web APP 可以在其中导航和访问文件。可以开发在虚拟、沙盒文件系统中读取、写入和创建文件和/或目录的 APP。

由于这是非标准 API,其规范目前不在标准轨道中,所以记住并非所有浏览器都有实现且可能仅实现一小部分,这点很重要。检查 浏览器兼容性 章节了解细节。

存在 2 种很类似的 API,取决于是期望异步行为还是同步行为。同步 API 旨在在用于 Worker 并返回期望值。异步 API 不会被阻塞,且函数和 API 不会返回值;相反,需要提供回调函数以在到达时处理响应。

Firefox 对文件和目录条目 API 的实现非常有限;不支持创建文件。仅用于访问由用户选择的文件在文件 <input> 元素 (见 HTMLInputElement ) 或当文件或目录被提供给 Web 站点或 APP 使用 拖放 。Firefox 未实现同步 API。小心谨慎检查使用 API 的任何部分的浏览器兼容性,并参阅 Firefox 中的文件和目录条目 API 支持 了解更多细节。

访问文件系统

有 2 种方式能访问当前规范草案中定义的文件系统:

异步 API

异步 API 应该用于大多数操作,以防止文件系统的访问阻塞整个浏览器若在主线程中使用。它包括以下接口:

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

提供采用所有必要锁来处理给定文件的工具。

元数据

规范

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

此 API 没有正式的 W3C 或 WHATWG (Web 超文本应用程序技术工作组) 规范。

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
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

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. 更新 GitHub 上的兼容性数据
桌面 移动
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

图例

完整支持

不支持

不支持

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: