FileReader: FileReader() constructor

Note: This feature is available in Web Workers.

The FileReader() constructor creates a new FileReader.

For details about how to use FileReader, see Using files from web applications.

Syntax

js
new FileReader()

Parameters

None.

Examples

The following code snippet shows creation of a FileReader object using the FileReader() constructor and subsequent usage of the object:

js
function printFile(file) {
  const reader = new FileReader();
  reader.onload = (evt) => {
    console.log(evt.target.result);
  };
  reader.readAsText(file);
}

Specifications

Specification
File API
# filereaderConstrctr

Browser compatibility

BCD tables only load in the browser

See also