1

So I got an application for a client that has a lot of files that need to be opened from within the application, pdf files mostly. I got everything working but when I tried to open the link:

<a class="btn btn-info" tooltip="Ver" href="{{ file.fileLocation }}" target="_blank" ><i class="fa fa-edit"></i></a>

It gives me the "Not Allowed to open local resource: file://srvnas/files/architecture_map.pdf" error, I know this is a Chrome security feature, I want to know what is the most efficient way to open this files. My backend works with asp.net core 2.1 and web api. Do I need to do some kind of fileserver? Do I need to open the files in another way? This folder I try to access is an open folder that is accessible to everyone so the security issue is not a problem to be honest.

Any points in the right direction is greatly appreciated.

V. Benavides
  • 533
  • 1
  • 7
  • 21
  • Possible duplicate of [Cannot open local file - Chrome: Not allowed to load local resource](https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource) – SiddAjmera Nov 29 '18 at 15:35

1 Answers1

0

One thing to take in consideration here when the user visits your website he/she makes the request to your web server

The web server will send the files to the client (HTML, CSS, JS)

So same as you have to send PDF file to the client.

If it's static files you can simply host them on the server and point the client to it.

E.g

Location on server

https://example.com/data/MyPdf.pdf

Link On Client side

<a class="btn btn-info" tooltip="Ver" href="example.com/data/MyPdf.pdf" target="_blank" ><i class="fa fa-edit"></i></a>

And if you have dynamic content you have to set up an API Endpoint which serves PDF content

IN order to get a link from API

you should return location from your API

[HttpGet]
public object GetPdfLink(int id)
{
    return new {Data="Path To Your PDF From DB"};
}

In your Angular Service extract Data property from response object and set it to your href

Mihir Dave
  • 3,954
  • 1
  • 12
  • 28
  • I have dynamic content, the link is pulled from the db where we store the file location. Do you have any directions for setting up an API endpoint? – V. Benavides Nov 29 '18 at 16:07