1

I have to take input from the user in CSV, and then extract values from a specific table. I have used the FileReader API to extract content from the CSV, but I'm getting object HTMLInputElement in the console.

This is my code

var input = document.querySelector('input[type="file"]');
var blob = new Blob([input], {
    encoding:"UTF-8",
    type: "text/csv;charset=UTF-8"
});

input.addEventListener('change',function(e) {
  console.log(input.files)
  const reader = new FileReader();
  reader.onload = function(e) {
    console.log(reader.result);
  }
  reader.readAsText(blob);

},false);

I should get the content from the csv, but I'm getting object HTMLInputElement

Object object
  • 872
  • 6
  • 18
JoyBhalla
  • 45
  • 8
  • The Blob is `HTMLInputElement.files[0]`. You don't need to create one, get the one your user provides. So your code should become `var input = document.querySelector('input[type="file"]'); input.addEventListener('change',function(e) { const reader = new FileReader(); reader.onload = function(e) { console.log(reader.result); } reader.readAsText(input.files[0]); }` – Kaiido May 22 '19 at 05:46

0 Answers0