This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



The FileReader object lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user’s computer, using File or Blob objects to specify the file or data to read. File objects may be obtained 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.


No properties.


The abort method is used to aborts the read operation. Upon return, the dom/Element/readyState will be DONE.
Returns partial Blob data representing the number of bytes currently loaded (as a fraction of the total), as an ArrayBuffer object, a fixed-length binary data buffer.
Returns the complete data of blob as a Data URL, essentially a Base64-encoded string of the file data.
Returns partial Blob data representing the number of bytes currently loaded (as a fraction of the total), decoded into memory according to the encoding determination.


No events.


Preview an image before upload

<!doctype html>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>Image preview example</title>
<script type="text/javascript">
oFReader = new FileReader(), rFilter = 'image/jpg';

oFReader.onload = function (oFREvent) {
  document.getElementById("uploadPreview").src =;

function loadImageFile() {
  if (document.getElementById("uploadImage").files.length === 0) { return; }
  var oFile = document.getElementById("uploadImage").files[0];
  if (!rFilter.test(oFile.type)) { alert("You must select a valid image file!"); return; }

<body onload="loadImageFile();">
  <form name="uploadForm">
          <td><img id="uploadPreview" style="width: 100px; height: 100px;" src="" alt="Image preview" /></td>
          <td><input id="uploadImage" type="file" name="myPhoto" onchange="loadImageFile();" /></td>

    <p><input type="submit" value="Send" /></p>

View live example


When the FileReader constructor is invoked, a new FileReader object is returned. This FileReader object enables asynchronous reads on individual File objects by firing progress events as the read occurs to event handler methods attached to the FileReader object.

Related specifications

W3C File API Specification
W3C Working Draft

See also

Other articles

Using files from web applications