1

In my app I'm viewing a list of files on the local machine (their paths are fetched from DB). When a file is being clicked, it should be opened. I tried the following with no success:

<a href="file:///c:/path/to/file">FileName</a>

When the user clicks the link above, nothing happens. When using chrome, I can see the following error message in the console (on firefox there's no message):

not allowed to load local resource

I have read this question, and understood that:

Mozilla browsers refuse to follow file URLs on a page that it has fetched with the HTTP protocol.

I also understood and that this feature was implemented in other browsers as well.

The presented files are not located in the server, but on the local machine. So I can't use a relative link (right?). Is there anyway to bypass this and create a link that opens a local file?

Aviran Katz
  • 741
  • 2
  • 8
  • 26

1 Answers1

2

You cannot access local resources from a website served over http because it is a security concern. Think of what would happen to your machine if any website could access files on it. You'll have other security restrictions for serving data from a different domain from your domain as well.

What exactly are you trying to accomplish by accessing a local file? Giving additional insight into the reason might get you more useful suggestions. Otherwise, the answer is that you can't and shouldn't do this.

Jason Lutz
  • 91
  • 5
  • I'm working on a demo web app, which has a feature of showing a list of files and loading any of them by clicking on it. In reality the file will be located on the server machine, which - in the demo - is going to be the client machine (localhost). For the demo we just need to make things work fast, even if it means writing bad code and rewriting it afterwards. From your answer I understand that my only option is to load the file from the server side (which currently doesn't exist)? – Aviran Katz Jun 06 '17 at 12:44