0

I have developed a script for myself to read and process local text and csv files on my computer using recent Chrome or Firefox browsers with the filereader api. The script will work on the computer, even though it is not connected to the internet or a local webserver.

The reasoning behind this is to have a standalone text file interrogator, which will work on almost any computer, requiring only a browser to execute and display reasonably formatted output. similar to an awk type application.

I use the filereader api and it works well.

I do not properly understand the workings of the browser, so my question may be very stupid.

Is it possible that my script can somehow pass the filename to the script filereader api, without having to choose a file from input type=file field.

eg I have a file called addresses.csv and it resides in the same directory as my html/js file with the filereader api code.

I want to simulate the choosing of a file, without accessing my local directory and without using a webserver, but a dropdown box of predefined filenames would be even better.

2 Answers 2

3

No, for security reasons its not possible, because otherwise people could open arbitrary files on the computers of their visitors which is definitely not intended.

This specification also assumes that the primary user interaction is with the element of HTML forms [HTML], and that all files that are being read by FileReader objects have first been selected by the user.

See http://www.w3.org/TR/FileAPI/#security-discussion

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

Comments

1

No you cannot. Javascript cannot read your local filesystem without the use of a file input or drag and drop files (html5) as it would be vulnerable to malicious use.

There was a start of a filesystem api which Chrome has included. But you cannot read/write to just any place you want on the filesystem, you can only do so to a sandboxed area on the filesystem. Wither or not they will continue to have this in future versions of Chrome though I do not know.

It also appears the W3C itself has discontinued the file system api

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.