File.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.
File()
建構子建立一個新的 File
物件實例
語法
var myFile = new File(bits, name[, options]);
參數
- bits
-
An
Array
ofArrayBuffer
,ArrayBufferView
,Blob
, orDOMString
objects — 或是由這些物件組成的集合。這是以 UTF-8 編碼的檔案內容。 - name
-
檔案名稱或檔案的路徑(
USVString
)。 - options 選擇性
-
物件選項,包含物件非必要的屬性,以下為可得到的屬性:
type
: 物件的 MIME 類型(DOMString
)將被放進檔案中,預設為 ""(空值)。lastModified
: 檔案最後修改時間,格式為毫秒,預設為Date.now()
.
範例
js
var file = new File(["foo"], "foo.txt", {
type: "text/plain",
});
規格
Specification |
---|
File API # file-constructor |