Home > Net >  How can I read a local file with a fixed path in Javascript? I only have the location of the file as
How can I read a local file with a fixed path in Javascript? I only have the location of the file as

Time:07-01

I am creating a web app where I already know the location of a file that needs to be uploaded. Note that all I have is the path (example: Users/username/Downloads or Users/username/Documents) or something like that. How can I get Javascript to read that file as a File object or as a binary string so that I can POST it to a server.

Additionally, this file is not a simple file like a JSON or a txt file. This file would usually be a Microsoft Word file.

CodePudding user response:

Due to security reasons, JavaScript executed from web apps have very limited access to the file system.

The best you can do is have the user select a file via a file input.

If having the web app user install a browser extension is acceptable, a browser extension may have more access to the user's file system. Here is an example extension that accesses a user's file system more directly: https://github.com/buggyj/savetiddlers

CodePudding user response:

I think you can't to read the any files from the front-end by javascript, It is not allowed to do so. But you can get the file path from front-end and then pass it to the app framwork or back-end to processing. Beacuse the app's framework or back-end has the ability to access system files. Whereafter, you can POST to the contents of the file to the web server.

  • Related