3

I am wondering if there is any method of reading file on the client side with javascript given the file name and path. I am aware of the method of reading through: input type="file".

What I mean is without opening up a file browser and selecting the file, just reading it with filename, like fopen.
If not an other method, how to instantiate a File object in javascript from filename and path?

Seeing the answers I thought of briefing a bit more on my purpose. I am not really making a webpage. I am using browser just as a software that is available on any system. The html pages will all be local. I am doing this way be so that I have the advantage of the power of js. Given this situation is there any way to set permission flags that will let it read files? Thank you.

2 Answers 2

5

There's the Drag 'n Drop API which would be the other option in reading files using JS


There will always be hurdles so that your code will not directly read from the client's filesystem. This is designed for privacy and security purposes.

  • Extensions/Plugins - sandboxing will be your enemy, limiting file system access

  • Java Applet - Needs a signed certificate to read the filesystem. A self-signed certificate will generate the "Will You Trust This Applet" prompt which would act as the security prompt.

  • Input type=file - gives the user the option to select the files or not

  • drag and drop - gives the user the option to drag in files or not

  • XHR - Same Origin Policy will block you, especially if you are executing the page locally and not on a server.

  • JSONP - Since this bypasses the SOP, however, your file should be in JSONP format.

Sign up to request clarification or add additional context in comments.

Comments

0

I found solution to my problem, here it is... It is true that we have restriction with javascript that whenever the user or the page requests for a file it has to go through that extra window that pops up, but if all the files that you may request are inside a known folder then you can rather ask the user to point the zipped folder instead. One can use tools like zip.js for opening a file that one needs in the zipped folder. Thank you :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.