File

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

备注: 此特性在 Web Worker 中可用。

File 接口提供有关文件的信息,并允许网页中的 JavaScript 访问其内容。

File 对象通常从用户使用 <input> 元素选择文件返回的 FileList 对象中检索,或者从拖放操作返回的 DataTransfer 对象中检索。

File 对象是一种特定类型的 Blob,并且可以在 Blob 可以使用的任何上下文中使用。特别地,以下 API 都接受 Blob 对象和 File 对象:

参见在 Web 应用程序使用文件了解更多信息和例子。

Blob File

构造函数

File()

返回一个新构建的 File 对象。

实例属性

File 接口还继承了 Blob 接口的属性。

File.lastModified 只读

返回文件的最后修改时间,以 UNIX 纪元(1970 年 1 月 1 日午夜)以来的毫秒为单位。

File.lastModifiedDate 已弃用 只读 非标准

返回 File 对象引用的文件的最后修改时间的 Date

File.name 只读

返回 File 对象引用的文件的名称。

File.webkitRelativePath 只读

返回 File 对象相对于 URL 的路径。

实例方法

File 接口还继承了 Blob 接口的方法。

规范

Specification
File API
# file-section

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
File
File() constructor
lastModified
lastModifiedDate
DeprecatedNon-standard
name
webkitRelativePath

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.
Has more compatibility info.

参见