AwaitedDOM/ File

The File interface provides information about files and allows JavaScript in a web page to access their content.
File objects are generally retrieved from a FileList object returned as a result of a user selecting files using the <input> element, from a drag and drop operation's DataTransfer object, or from the mozGetAsFile() API on an HTMLCanvasElement.
A File object is a specific kind of a Blob, and can be used in any context that a Blob can. In particular, FileReader, URL.createObjectURL(), createImageBitmap(), and XMLHttpRequest.send() accept both Blobs and Files.
See Using files from web applications for more information and examples.

Properties

.lastModified
W3C

Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight).

Type: Promise<number>

.name
W3C

Returns the name of the file referenced by the File object.

Type: Promise<string>

.size
W3C

The size, in bytes, of the data contained in the Blob object.

Type: Promise<number>

.type
W3C

A string indicating the MIME type of the data contained in the Blob. If the type is unknown, this string is empty.

Type: Promise<string>

Methods

.arrayBuffer()
W3C

Returns a promise that resolves with an ArrayBuffer containing the entire contents of the Blob as binary data.

Returns: Promise<ArrayBuffer>

.slice(start?, end?, contentType?)
W3C

Returns a new Blob object containing the data in the specified range of bytes of the blob on which it's called.

Arguments:

  • start number. An index into the Blob indicating the first byte to include in the new Blob. If you specify a negative value, it's treated as an offset from the end of the Blob toward the beginning. For example, -10 would be the 10th from last byte in the Blob. The default value is 0. If you specify a value for start that is larger than the size of the source Blob, the returned Blob has size 0 and contains no data.
  • end number. An index into the Blob indicating the first byte that will not be included in the new Blob (i.e. the byte exactly at this index is not included). If you specify a negative value, it's treated as an offset from the end of the Blob toward the beginning. For example, -10 would be the 10th from last byte in the Blob. The default value is size.
  • contentType string. The content type to assign to the new Blob; this will be the value of its type property. The default value is an empty string.

Returns: Promise<Blob>

.text()
W3C

Returns a promise that resolves with a string containing the entire contents of the Blob interpreted as UTF-8 text.

Returns: Promise<string>

Unimplemented Specs

Methods

stream()

Edit this page on GitHub