0

I'm trying to make a button to upload any csv file to my function, I used to read it locally :

var ccs=loadCSV("sankey.csv");

But now i want to great a button to chose the file, I want to have the value of the var after uploading because of the function that I'm using in my code. I started with something

<input type="file" name="filename" id="filename">
  <div id="csvimporthint"></div>

How to get file reader?

vp_arth
  • 14,461
  • 4
  • 37
  • 66
Chis
  • 131
  • 10

1 Answers1

1

If I understand the question correctly, you want to be able to read a file on client side. If that's the case, FileReader is what you'd want to use.

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.

There's a great tutorial on how to use Filereader that you should read.

zhirzh
  • 3,273
  • 3
  • 25
  • 30
  • Please [avoid link only answers](http://meta.stackoverflow.com/tags/link-only-answers/info). Answers that are "barely more than a link to an external site” [may be deleted](http://stackoverflow.com/help/deleted-answers). – Quentin Apr 12 '16 at 08:39
  • Got it. Will add more to the answer – zhirzh Apr 12 '16 at 08:42
  • This answer provide a solution: `FileReader API`. It does not provide full implemented code, but it even better, because allows OP to make own work byself. – vp_arth Apr 12 '16 at 08:43
  • @vp_arth — That isn't how Stackoverflow works. – Quentin Apr 12 '16 at 08:45