Read contents from input type file

Read input type file contents –
File content can be read using FileReader function of javascript. Here is an example for explanation –

Create HTML (input field and a div where we have to show the content of file) –

<input type=”file” name=”inputfile” onchange=”readinputfile()”>
<div class=”showfilecontent”></div>

Now call JS function –

const reader = new FileReader()
function readinputfile (input) {
const input = input.files[0]
reader.onload = function (e) {
document.querySelector(‘. showfilecontent ‘).innerText =;



For more related queries, please VISIT.

In case, if you did not find your solution or have any query/question, please contact us.