get the data of uploaded file in javascript

The Solution to get the data of uploaded file in javascript is

The example below is based on the html5rocks solution. It uses the browser's FileReader() function. Newer browsers only.


In this example, the user selects an HTML file. It uploaded into the <textarea>.

<form enctype="multipart/form-data">
<input id="upload" type=file   accept="text/html" name="files[]" size=30>

<textarea class="form-control" rows=35 cols=120 id="ms_word_filtered_html"></textarea>

function handleFileSelect(evt) {
    var files =; // FileList object

    // use the 1st file from the list
    f = files[0];

    var reader = new FileReader();

    // Closure to capture the file information.
    reader.onload = (function(theFile) {
        return function(e) {

          jQuery( '#ms_word_filtered_html' ).val( );

      // Read in the image file as a data URL.

  document.getElementById('upload').addEventListener('change', handleFileSelect, false);

~ Answered on 2016-09-15 16:15:14

Most Viewed Questions: