File.File()

File() 建構子建立一個新的 File 物件實例

語法

var myFile = new File(bits, name[, options]);

參數

bits

An Array of ArrayBuffer, ArrayBufferView (en-US), Blob, or DOMString objects — 或是由這些物件組成的集合。這是以 UTF-8 編碼的檔案內容。

name

檔案名稱或檔案的路徑(USVString (en-US))。

options 選擇性

物件選項,包含物件非必要的屬性,以下為可得到的屬性:

  • type: 物件的 MIME 類型(DOMString )將被放進檔案中,預設為 ""(空值)。
  • lastModified: 檔案最後修改時間,格式為毫秒,預設為 Date.now().

範例

js
var file = new File(["foo"], "foo.txt", {
  type: "text/plain",
});

規格

Specification
File API
# file-constructor

瀏覽器相容性

BCD tables only load in the browser

看更多