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

1
  • In few words, you can't do that from a browser. You can ask the user to upload the file using the <input type="file"/> 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 for information on using the upload approach. Commented Aug 25, 2018 at 11:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.