FileReader.readAsText

  • Revision slug: Web/API/FileReader.readAsText
  • Revision title: FileReader.readAsText
  • Revision id: 482757
  • Created:
  • Creator: Jeremie
  • Is current revision? No
  • Comment

Revision Content

Summary

The readAsText method is used to starts reading the contents of the specified {{domxref("Blob")}} or {{domxref("File")}}. When the read operation is finished, the {{domxref("FileReader.readyState","readyState")}} becomes DONE, and the {{event("loadend")}} is triggered. At that time, the {{domxref("FileReader.result","result")}} attribute contains the contents of the file as a text string.

Syntaxe

instanceOfFileReader.readAsText(blob[, encoding]);

Parameters

blob
The {{domxref("Blob")}} or {{domxref("File")}} from which to read.
encoding {{optional_inline}}
A string indicating the encoding to use for the returned data. By default, UTF-8 is assumed if this parameter is not specified.

Specifications

{{page("/en-US/docs/Web/API/FileReader","Specifications")}}

Browser compatibility

{{page("/en-US/docs/Web/API/FileReader","Browser compatibility")}}

See also

  • {{domxref("FileReader")}}

Revision Source

<h2 id="Summary">Summary</h2>
<p>The <code>readAsText</code> method is used to starts reading the contents of the specified {{domxref("Blob")}} or {{domxref("File")}}. When the read operation is finished, the {{domxref("FileReader.readyState","readyState")}} becomes <code>DONE</code>, and the {{event("loadend")}} is triggered. At that time, the {{domxref("FileReader.result","result")}} attribute contains the contents of the file as a text string.</p>
<h2 id="Syntaxe">Syntaxe</h2>
<pre>
<em>instanceOfFileReader</em>.readAsText(blob[, encoding]);</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
  <dt>
    <code>blob</code></dt>
  <dd>
    The {{domxref("Blob")}} or {{domxref("File")}} from which to read.</dd>
  <dt>
    encoding {{optional_inline}}</dt>
  <dd>
    A string indicating the encoding to use for the returned data. By default, UTF-8 is assumed if this parameter is not specified.</dd>
</dl>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">Specifications</h2>
<p>{{page("/en-US/docs/Web/API/FileReader","Specifications")}}</p>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<p>{{page("/en-US/docs/Web/API/FileReader","Browser compatibility")}}</p>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{domxref("FileReader")}}</li>
</ul>
Revert to this revision