FileReader()

The FileReader() constructor creates a new FileReader.

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

Syntax

const reader = new FileReader();

Parameters

None.

Example

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

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

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
FileReader
7
12
3.6
10
≤12.1
6
≤37
18
32
≤12.1
6
1.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/FileReader/FileReader