2

I have full path of file e.g "D:\File\1.xml" and want to read contents of it in javascript. I tried using File and FileReader API's but no success. Following piece of code I tried.

var path = "D:\File\1.xml";
var file = new File(path); //Doesn't work
var fileReader = new FileReader(file); //filereader expects file object

Can anyone help out how to read local files from file path in javascript or how to create File object successfuly from path. Thanks

Ankur
  • 21
  • 1
  • 2
  • 4
  • In few words, you can't do that from a browser. You can ask the user to upload the file using the `` element, and use the File API to read it then (before the actual upload), but you can't do it given a file path, from the browser. See [Reading file contents on the client-side in javascript in various browsers](//stackoverflow.com/q/750032) for information on using the upload approach. – Heretic Monkey Aug 25 '18 at 11:42

0 Answers0