File()
构造器创建新的 File
对象实例。
语法
var myFile = new File(bits, name[, options]);
参数
- bits
- 一个包含
ArrayBuffer
,ArrayBufferView
,Blob
,或者DOMString
对象的Array
— 或者任何这些对象的组合。这是 UTF-8 编码的文件内容。 - name
USVString
,表示文件名称,或者文件路径。- options 可选
- 选项对象,包含文件的可选属性。可用的选项如下:
type
:DOMString
,表示将要放到文件中的内容的 MIME 类型。默认值为""
。lastModified
: 数值,表示文件最后修改时间的 Unix 时间戳(毫秒)。默认值为Date.now()
。
示例
var file = new File(["foo"], "foo.txt", {
type: "text/plain",
});
规范
Specification | Status | Comment |
---|---|---|
File API | Working Draft | Initial definition |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 13 | (Yes) | 7 (7) | 10.0 | 11.5 | 6.0 |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 未实现 | (Yes) | 7.0 (7) | 未实现 | 11.1 | 6.0 |